Skip to content

Commit c81f8fc

Browse files
TahaTesserpull[bot]
authored andcommitted
Deprecate ButtonBar, ButtonBarThemeData, and ThemeData.buttonBarTheme (flutter#145523)
fixes [Deprecate `ButtonBar`](flutter#127955) ### Code sample <details> <summary>expand to view the code sample</summary> ```dart import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @OverRide Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( buttonBarTheme: const ButtonBarThemeData( alignment: MainAxisAlignment.spaceEvenly, ), ), home: Scaffold( body: ButtonBar( alignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ TextButton( onPressed: () {}, child: const Text('Button 1'), ), TextButton( onPressed: () {}, child: const Text('Button 2'), ), TextButton( onPressed: () {}, child: const Text('Button 3'), ), ], ), ), ); } } ``` </details> ## Data driven fix ### Before executing `dart fix --apply` ```dart return MaterialApp( theme: ThemeData( buttonBarTheme: const ButtonBarThemeData( alignment: MainAxisAlignment.spaceEvenly, ), ), home: Scaffold( body: ButtonBar( alignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ TextButton( onPressed: () {}, child: const Text('Button 1'), ), TextButton( onPressed: () {}, child: const Text('Button 2'), ), TextButton( onPressed: () {}, child: const Text('Button 3'), ), ], ), ), ); ``` ### After executing `dart fix --apply` ```dart return MaterialApp( theme: ThemeData( ), home: Scaffold( body: OverflowBar( alignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ TextButton( onPressed: () {}, child: const Text('Button 1'), ), TextButton( onPressed: () {}, child: const Text('Button 2'), ), TextButton( onPressed: () {}, child: const Text('Button 3'), ), ], ), ), ); ```
1 parent d1cf32a commit c81f8fc

File tree

7 files changed

+136
-15
lines changed

7 files changed

+136
-15
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2014 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
# For details regarding the *Flutter Fix* feature, see
6+
# https://flutter.dev/docs/development/tools/flutter-fix
7+
8+
# Please add new fixes to the top of the file, separated by one blank line
9+
# from other fixes. In a comment, include a link to the PR where the change
10+
# requiring the fix was made.
11+
12+
# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md
13+
# file for instructions on testing these data driven fixes.
14+
15+
# For documentation about this file format, see
16+
# https://dart.dev/go/data-driven-fixes.
17+
18+
# * Fixes in this file are for ButtonBar from the Material library. *
19+
# For fixes to
20+
# * AppBarTheme: fix_app_bar_theme.yaml
21+
# * AppBar: fix_app_bar.yaml
22+
# * ButtonBar: fix_button_bar.yaml
23+
# * ColorScheme: fix_color_scheme.yaml
24+
# * Material (general): fix_material.yaml
25+
# * SliverAppBar: fix_sliver_app_bar.yaml
26+
# * TextTheme: fix_text_theme.yaml
27+
# * ThemeData: fix_theme_data.yaml
28+
version: 1
29+
transforms:
30+
# Changes made in https://github.com/flutter/flutter/pull/145523
31+
- title: "Migrate to 'OverflowBar'"
32+
date: 2024-02-28
33+
element:
34+
uris: [ 'material.dart' ]
35+
class: 'ButtonBar'
36+
changes:
37+
- kind: 'rename'
38+
newName: 'OverflowBar'
39+
40+
# Before adding a new fix: read instructions at the top of this file.

packages/flutter/lib/fix_data/fix_material/fix_theme_data.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,4 +1698,15 @@ transforms:
16981698
- kind: 'removeParameter'
16991699
name: 'useMaterial3'
17001700

1701+
# Changes made in https://github.com/flutter/flutter/pull/145523
1702+
- title: "Remove 'buttonBarTheme'"
1703+
date: 2024-04-28
1704+
element:
1705+
uris: [ 'material.dart' ]
1706+
constructor: ''
1707+
inClass: 'ThemeData'
1708+
changes:
1709+
- kind: 'removeParameter'
1710+
name: 'buttonBarTheme'
1711+
17011712
# Before adding a new fix: read instructions at the top of this file.

packages/flutter/lib/src/material/button_bar.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,19 @@ import 'dialog.dart';
7979
/// * [Card], at the bottom of which it is common to place a [ButtonBar].
8080
/// * [Dialog], which uses a [ButtonBar] for its actions.
8181
/// * [ButtonBarTheme], which configures the [ButtonBar].
82+
@Deprecated(
83+
'Use OverflowBar instead. '
84+
'This feature was deprecated after v3.21.0-10.0.pre.',
85+
)
8286
class ButtonBar extends StatelessWidget {
8387
/// Creates a button bar.
8488
///
8589
/// Both [buttonMinWidth] and [buttonHeight] must be non-negative if they
8690
/// are not null.
91+
@Deprecated(
92+
'Use OverflowBar instead. '
93+
'This feature was deprecated after v3.21.0-10.0.pre.',
94+
)
8795
const ButtonBar({
8896
super.key,
8997
this.alignment,

packages/flutter/lib/src/material/button_bar_theme.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,20 @@ import 'theme.dart';
2727
/// its subtree.
2828
/// * [ButtonBar], which uses this to configure itself and its children
2929
/// button widgets.
30+
@Deprecated(
31+
'Use OverflowBar instead. '
32+
'This feature was deprecated after v3.21.0-10.0.pre.',
33+
)
3034
@immutable
3135
class ButtonBarThemeData with Diagnosticable {
3236
/// Constructs the set of properties used to configure [ButtonBar] widgets.
3337
///
3438
/// Both [buttonMinWidth] and [buttonHeight] must be non-negative if they
3539
/// are not null.
40+
@Deprecated(
41+
'Use OverflowBar instead. '
42+
'This feature was deprecated after v3.21.0-10.0.pre.',
43+
)
3644
const ButtonBarThemeData({
3745
this.alignment,
3846
this.mainAxisSize,

packages/flutter/lib/src/material/theme_data.dart

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ class ThemeData with Diagnosticable {
327327
BottomAppBarTheme? bottomAppBarTheme,
328328
BottomNavigationBarThemeData? bottomNavigationBarTheme,
329329
BottomSheetThemeData? bottomSheetTheme,
330-
ButtonBarThemeData? buttonBarTheme,
331330
ButtonThemeData? buttonTheme,
332331
CardTheme? cardTheme,
333332
CheckboxThemeData? checkboxTheme,
@@ -366,6 +365,11 @@ class ThemeData with Diagnosticable {
366365
TimePickerThemeData? timePickerTheme,
367366
ToggleButtonsThemeData? toggleButtonsTheme,
368367
TooltipThemeData? tooltipTheme,
368+
@Deprecated(
369+
'Use OverflowBar instead. '
370+
'This feature was deprecated after v3.21.0-10.0.pre.',
371+
)
372+
ButtonBarThemeData? buttonBarTheme,
369373
}) {
370374
// GENERAL CONFIGURATION
371375
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
@@ -500,7 +504,6 @@ class ThemeData with Diagnosticable {
500504
bottomAppBarTheme ??= const BottomAppBarTheme();
501505
bottomNavigationBarTheme ??= const BottomNavigationBarThemeData();
502506
bottomSheetTheme ??= const BottomSheetThemeData();
503-
buttonBarTheme ??= const ButtonBarThemeData();
504507
cardTheme ??= const CardTheme();
505508
checkboxTheme ??= const CheckboxThemeData();
506509
chipTheme ??= const ChipThemeData();
@@ -538,6 +541,8 @@ class ThemeData with Diagnosticable {
538541
timePickerTheme ??= const TimePickerThemeData();
539542
toggleButtonsTheme ??= const ToggleButtonsThemeData();
540543
tooltipTheme ??= const TooltipThemeData();
544+
// DEPRECATED (newest deprecations at the bottom)
545+
buttonBarTheme ??= const ButtonBarThemeData();
541546
return ThemeData.raw(
542547
// For the sanity of the reader, make sure these properties are in the same
543548
// order in every place that they are separated by section comments (e.g.
@@ -591,7 +596,6 @@ class ThemeData with Diagnosticable {
591596
bottomAppBarTheme: bottomAppBarTheme,
592597
bottomNavigationBarTheme: bottomNavigationBarTheme,
593598
bottomSheetTheme: bottomSheetTheme,
594-
buttonBarTheme: buttonBarTheme,
595599
buttonTheme: buttonTheme,
596600
cardTheme: cardTheme,
597601
checkboxTheme: checkboxTheme,
@@ -630,6 +634,8 @@ class ThemeData with Diagnosticable {
630634
timePickerTheme: timePickerTheme,
631635
toggleButtonsTheme: toggleButtonsTheme,
632636
tooltipTheme: tooltipTheme,
637+
// DEPRECATED (newest deprecations at the bottom)
638+
buttonBarTheme: buttonBarTheme,
633639
);
634640
}
635641

@@ -696,7 +702,6 @@ class ThemeData with Diagnosticable {
696702
required this.bottomAppBarTheme,
697703
required this.bottomNavigationBarTheme,
698704
required this.bottomSheetTheme,
699-
required this.buttonBarTheme,
700705
required this.buttonTheme,
701706
required this.cardTheme,
702707
required this.checkboxTheme,
@@ -735,7 +740,17 @@ class ThemeData with Diagnosticable {
735740
required this.timePickerTheme,
736741
required this.toggleButtonsTheme,
737742
required this.tooltipTheme,
738-
});
743+
// DEPRECATED (newest deprecations at the bottom)
744+
@Deprecated(
745+
'Use OverflowBar instead. '
746+
'This feature was deprecated after v3.21.0-10.0.pre.',
747+
)
748+
ButtonBarThemeData? buttonBarTheme,
749+
}) : // DEPRECATED (newest deprecations at the bottom)
750+
// should not be `required`, use getter pattern to avoid breakages.
751+
_buttonBarTheme = buttonBarTheme,
752+
// DEPRECATED (newest deprecations at the bottom)
753+
assert(buttonBarTheme != null);
739754

740755
/// Create a [ThemeData] based on the colors in the given [colorScheme] and
741756
/// text styles of the optional [textTheme].
@@ -1248,9 +1263,6 @@ class ThemeData with Diagnosticable {
12481263
/// A theme for customizing the color, elevation, and shape of a bottom sheet.
12491264
final BottomSheetThemeData bottomSheetTheme;
12501265

1251-
/// A theme for customizing the appearance and layout of [ButtonBar] widgets.
1252-
final ButtonBarThemeData buttonBarTheme;
1253-
12541266
/// Defines the default configuration of button widgets, like [DropdownButton]
12551267
/// and [ButtonBar].
12561268
final ButtonThemeData buttonTheme;
@@ -1390,6 +1402,14 @@ class ThemeData with Diagnosticable {
13901402
/// This is the value returned from [TooltipTheme.of].
13911403
final TooltipThemeData tooltipTheme;
13921404

1405+
/// A theme for customizing the appearance and layout of [ButtonBar] widgets.
1406+
@Deprecated(
1407+
'Use OverflowBar instead. '
1408+
'This feature was deprecated after v3.21.0-10.0.pre.',
1409+
)
1410+
ButtonBarThemeData get buttonBarTheme => _buttonBarTheme!;
1411+
final ButtonBarThemeData? _buttonBarTheme;
1412+
13931413
/// Creates a copy of this theme but with the given fields replaced with the new values.
13941414
///
13951415
/// The [brightness] value is applied to the [colorScheme].
@@ -1449,7 +1469,6 @@ class ThemeData with Diagnosticable {
14491469
BottomAppBarTheme? bottomAppBarTheme,
14501470
BottomNavigationBarThemeData? bottomNavigationBarTheme,
14511471
BottomSheetThemeData? bottomSheetTheme,
1452-
ButtonBarThemeData? buttonBarTheme,
14531472
ButtonThemeData? buttonTheme,
14541473
CardTheme? cardTheme,
14551474
CheckboxThemeData? checkboxTheme,
@@ -1497,6 +1516,11 @@ class ThemeData with Diagnosticable {
14971516
'This feature was deprecated after v3.13.0-0.2.pre.',
14981517
)
14991518
bool? useMaterial3,
1519+
@Deprecated(
1520+
'Use OverflowBar instead. '
1521+
'This feature was deprecated after v3.21.0-10.0.pre.',
1522+
)
1523+
ButtonBarThemeData? buttonBarTheme,
15001524
}) {
15011525
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
15021526
return ThemeData.raw(
@@ -1554,7 +1578,6 @@ class ThemeData with Diagnosticable {
15541578
bottomAppBarTheme: bottomAppBarTheme ?? this.bottomAppBarTheme,
15551579
bottomNavigationBarTheme: bottomNavigationBarTheme ?? this.bottomNavigationBarTheme,
15561580
bottomSheetTheme: bottomSheetTheme ?? this.bottomSheetTheme,
1557-
buttonBarTheme: buttonBarTheme ?? this.buttonBarTheme,
15581581
buttonTheme: buttonTheme ?? this.buttonTheme,
15591582
cardTheme: cardTheme ?? this.cardTheme,
15601583
checkboxTheme: checkboxTheme ?? this.checkboxTheme,
@@ -1593,6 +1616,7 @@ class ThemeData with Diagnosticable {
15931616
timePickerTheme: timePickerTheme ?? this.timePickerTheme,
15941617
toggleButtonsTheme: toggleButtonsTheme ?? this.toggleButtonsTheme,
15951618
tooltipTheme: tooltipTheme ?? this.tooltipTheme,
1619+
buttonBarTheme: buttonBarTheme ?? _buttonBarTheme,
15961620
);
15971621
}
15981622

@@ -1747,7 +1771,6 @@ class ThemeData with Diagnosticable {
17471771
bottomAppBarTheme: BottomAppBarTheme.lerp(a.bottomAppBarTheme, b.bottomAppBarTheme, t),
17481772
bottomNavigationBarTheme: BottomNavigationBarThemeData.lerp(a.bottomNavigationBarTheme, b.bottomNavigationBarTheme, t),
17491773
bottomSheetTheme: BottomSheetThemeData.lerp(a.bottomSheetTheme, b.bottomSheetTheme, t)!,
1750-
buttonBarTheme: ButtonBarThemeData.lerp(a.buttonBarTheme, b.buttonBarTheme, t)!,
17511774
buttonTheme: t < 0.5 ? a.buttonTheme : b.buttonTheme,
17521775
cardTheme: CardTheme.lerp(a.cardTheme, b.cardTheme, t),
17531776
checkboxTheme: CheckboxThemeData.lerp(a.checkboxTheme, b.checkboxTheme, t),
@@ -1786,6 +1809,7 @@ class ThemeData with Diagnosticable {
17861809
timePickerTheme: TimePickerThemeData.lerp(a.timePickerTheme, b.timePickerTheme, t),
17871810
toggleButtonsTheme: ToggleButtonsThemeData.lerp(a.toggleButtonsTheme, b.toggleButtonsTheme, t)!,
17881811
tooltipTheme: TooltipThemeData.lerp(a.tooltipTheme, b.tooltipTheme, t)!,
1812+
buttonBarTheme: ButtonBarThemeData.lerp(a.buttonBarTheme, b.buttonBarTheme, t),
17891813
);
17901814
}
17911815

@@ -1847,7 +1871,6 @@ class ThemeData with Diagnosticable {
18471871
other.bottomAppBarTheme == bottomAppBarTheme &&
18481872
other.bottomNavigationBarTheme == bottomNavigationBarTheme &&
18491873
other.bottomSheetTheme == bottomSheetTheme &&
1850-
other.buttonBarTheme == buttonBarTheme &&
18511874
other.buttonTheme == buttonTheme &&
18521875
other.cardTheme == cardTheme &&
18531876
other.checkboxTheme == checkboxTheme &&
@@ -1885,7 +1908,8 @@ class ThemeData with Diagnosticable {
18851908
other.textSelectionTheme == textSelectionTheme &&
18861909
other.timePickerTheme == timePickerTheme &&
18871910
other.toggleButtonsTheme == toggleButtonsTheme &&
1888-
other.tooltipTheme == tooltipTheme;
1911+
other.tooltipTheme == tooltipTheme &&
1912+
other.buttonBarTheme == buttonBarTheme;
18891913
}
18901914

18911915
@override
@@ -1945,7 +1969,6 @@ class ThemeData with Diagnosticable {
19451969
bottomAppBarTheme,
19461970
bottomNavigationBarTheme,
19471971
bottomSheetTheme,
1948-
buttonBarTheme,
19491972
buttonTheme,
19501973
cardTheme,
19511974
checkboxTheme,
@@ -1984,6 +2007,8 @@ class ThemeData with Diagnosticable {
19842007
timePickerTheme,
19852008
toggleButtonsTheme,
19862009
tooltipTheme,
2010+
// DEPRECATED (newest deprecations at the bottom)
2011+
buttonBarTheme,
19872012
];
19882013
return Object.hashAll(values);
19892014
}
@@ -2044,7 +2069,6 @@ class ThemeData with Diagnosticable {
20442069
properties.add(DiagnosticsProperty<BottomAppBarTheme>('bottomAppBarTheme', bottomAppBarTheme, defaultValue: defaultData.bottomAppBarTheme, level: DiagnosticLevel.debug));
20452070
properties.add(DiagnosticsProperty<BottomNavigationBarThemeData>('bottomNavigationBarTheme', bottomNavigationBarTheme, defaultValue: defaultData.bottomNavigationBarTheme, level: DiagnosticLevel.debug));
20462071
properties.add(DiagnosticsProperty<BottomSheetThemeData>('bottomSheetTheme', bottomSheetTheme, defaultValue: defaultData.bottomSheetTheme, level: DiagnosticLevel.debug));
2047-
properties.add(DiagnosticsProperty<ButtonBarThemeData>('buttonBarTheme', buttonBarTheme, defaultValue: defaultData.buttonBarTheme, level: DiagnosticLevel.debug));
20482072
properties.add(DiagnosticsProperty<ButtonThemeData>('buttonTheme', buttonTheme, level: DiagnosticLevel.debug));
20492073
properties.add(DiagnosticsProperty<CardTheme>('cardTheme', cardTheme, level: DiagnosticLevel.debug));
20502074
properties.add(DiagnosticsProperty<CheckboxThemeData>('checkboxTheme', checkboxTheme, defaultValue: defaultData.checkboxTheme, level: DiagnosticLevel.debug));
@@ -2083,6 +2107,8 @@ class ThemeData with Diagnosticable {
20832107
properties.add(DiagnosticsProperty<TimePickerThemeData>('timePickerTheme', timePickerTheme, defaultValue: defaultData.timePickerTheme, level: DiagnosticLevel.debug));
20842108
properties.add(DiagnosticsProperty<ToggleButtonsThemeData>('toggleButtonsTheme', toggleButtonsTheme, level: DiagnosticLevel.debug));
20852109
properties.add(DiagnosticsProperty<TooltipThemeData>('tooltipTheme', tooltipTheme, level: DiagnosticLevel.debug));
2110+
// DEPRECATED (newest deprecations at the bottom)
2111+
properties.add(DiagnosticsProperty<ButtonBarThemeData>('buttonBarTheme', buttonBarTheme, defaultValue: defaultData.buttonBarTheme, level: DiagnosticLevel.debug));
20862112
}
20872113
}
20882114

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
7+
void main() {
8+
// Changes made in https://github.com/flutter/flutter/pull/145523
9+
ButtonBar();
10+
11+
// Changes made in https://github.com/flutter/flutter/pull/145523
12+
ThemeData theme = ThemeData();
13+
theme = ThemeData(buttonBarTheme: ButtonBarThemeData());
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
7+
void main() {
8+
// Changes made in https://github.com/flutter/flutter/pull/145523
9+
OverflowBar();
10+
11+
// Changes made in https://github.com/flutter/flutter/pull/145523
12+
ThemeData theme = ThemeData();
13+
theme = ThemeData();
14+
}

0 commit comments

Comments
 (0)