Deprecate ButtonBar, ButtonBarThemeData, and ThemeData.buttonBarTheme (#145523)

fixes [Deprecate `ButtonBar`](https://github.com/flutter/flutter/issues/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'),
            ),
          ],
        ),
      ),
    );
```
This commit is contained in:
Taha Tesser 2024-04-01 14:39:48 +03:00 committed by GitHub
parent 40dda2b4bb
commit e85340e1e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 136 additions and 15 deletions

View File

@ -0,0 +1,40 @@
# Copyright 2014 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# For details regarding the *Flutter Fix* feature, see
# https://flutter.dev/docs/development/tools/flutter-fix
# Please add new fixes to the top of the file, separated by one blank line
# from other fixes. In a comment, include a link to the PR where the change
# requiring the fix was made.
# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md
# file for instructions on testing these data driven fixes.
# For documentation about this file format, see
# https://dart.dev/go/data-driven-fixes.
# * Fixes in this file are for ButtonBar from the Material library. *
# For fixes to
# * AppBarTheme: fix_app_bar_theme.yaml
# * AppBar: fix_app_bar.yaml
# * ButtonBar: fix_button_bar.yaml
# * ColorScheme: fix_color_scheme.yaml
# * Material (general): fix_material.yaml
# * SliverAppBar: fix_sliver_app_bar.yaml
# * TextTheme: fix_text_theme.yaml
# * ThemeData: fix_theme_data.yaml
version: 1
transforms:
# Changes made in https://github.com/flutter/flutter/pull/145523
- title: "Migrate to 'OverflowBar'"
date: 2024-02-28
element:
uris: [ 'material.dart' ]
class: 'ButtonBar'
changes:
- kind: 'rename'
newName: 'OverflowBar'
# Before adding a new fix: read instructions at the top of this file.

View File

@ -1698,4 +1698,15 @@ transforms:
- kind: 'removeParameter'
name: 'useMaterial3'
# Changes made in https://github.com/flutter/flutter/pull/145523
- title: "Remove 'buttonBarTheme'"
date: 2024-04-28
element:
uris: [ 'material.dart' ]
constructor: ''
inClass: 'ThemeData'
changes:
- kind: 'removeParameter'
name: 'buttonBarTheme'
# Before adding a new fix: read instructions at the top of this file.

View File

@ -79,11 +79,19 @@ import 'dialog.dart';
/// * [Card], at the bottom of which it is common to place a [ButtonBar].
/// * [Dialog], which uses a [ButtonBar] for its actions.
/// * [ButtonBarTheme], which configures the [ButtonBar].
@Deprecated(
'Use OverflowBar instead. '
'This feature was deprecated after v3.21.0-10.0.pre.',
)
class ButtonBar extends StatelessWidget {
/// Creates a button bar.
///
/// Both [buttonMinWidth] and [buttonHeight] must be non-negative if they
/// are not null.
@Deprecated(
'Use OverflowBar instead. '
'This feature was deprecated after v3.21.0-10.0.pre.',
)
const ButtonBar({
super.key,
this.alignment,

View File

@ -27,12 +27,20 @@ import 'theme.dart';
/// its subtree.
/// * [ButtonBar], which uses this to configure itself and its children
/// button widgets.
@Deprecated(
'Use OverflowBar instead. '
'This feature was deprecated after v3.21.0-10.0.pre.',
)
@immutable
class ButtonBarThemeData with Diagnosticable {
/// Constructs the set of properties used to configure [ButtonBar] widgets.
///
/// Both [buttonMinWidth] and [buttonHeight] must be non-negative if they
/// are not null.
@Deprecated(
'Use OverflowBar instead. '
'This feature was deprecated after v3.21.0-10.0.pre.',
)
const ButtonBarThemeData({
this.alignment,
this.mainAxisSize,

View File

@ -327,7 +327,6 @@ class ThemeData with Diagnosticable {
BottomAppBarTheme? bottomAppBarTheme,
BottomNavigationBarThemeData? bottomNavigationBarTheme,
BottomSheetThemeData? bottomSheetTheme,
ButtonBarThemeData? buttonBarTheme,
ButtonThemeData? buttonTheme,
CardTheme? cardTheme,
CheckboxThemeData? checkboxTheme,
@ -366,6 +365,11 @@ class ThemeData with Diagnosticable {
TimePickerThemeData? timePickerTheme,
ToggleButtonsThemeData? toggleButtonsTheme,
TooltipThemeData? tooltipTheme,
@Deprecated(
'Use OverflowBar instead. '
'This feature was deprecated after v3.21.0-10.0.pre.',
)
ButtonBarThemeData? buttonBarTheme,
}) {
// GENERAL CONFIGURATION
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
@ -500,7 +504,6 @@ class ThemeData with Diagnosticable {
bottomAppBarTheme ??= const BottomAppBarTheme();
bottomNavigationBarTheme ??= const BottomNavigationBarThemeData();
bottomSheetTheme ??= const BottomSheetThemeData();
buttonBarTheme ??= const ButtonBarThemeData();
cardTheme ??= const CardTheme();
checkboxTheme ??= const CheckboxThemeData();
chipTheme ??= const ChipThemeData();
@ -538,6 +541,8 @@ class ThemeData with Diagnosticable {
timePickerTheme ??= const TimePickerThemeData();
toggleButtonsTheme ??= const ToggleButtonsThemeData();
tooltipTheme ??= const TooltipThemeData();
// DEPRECATED (newest deprecations at the bottom)
buttonBarTheme ??= const ButtonBarThemeData();
return ThemeData.raw(
// For the sanity of the reader, make sure these properties are in the same
// order in every place that they are separated by section comments (e.g.
@ -591,7 +596,6 @@ class ThemeData with Diagnosticable {
bottomAppBarTheme: bottomAppBarTheme,
bottomNavigationBarTheme: bottomNavigationBarTheme,
bottomSheetTheme: bottomSheetTheme,
buttonBarTheme: buttonBarTheme,
buttonTheme: buttonTheme,
cardTheme: cardTheme,
checkboxTheme: checkboxTheme,
@ -630,6 +634,8 @@ class ThemeData with Diagnosticable {
timePickerTheme: timePickerTheme,
toggleButtonsTheme: toggleButtonsTheme,
tooltipTheme: tooltipTheme,
// DEPRECATED (newest deprecations at the bottom)
buttonBarTheme: buttonBarTheme,
);
}
@ -696,7 +702,6 @@ class ThemeData with Diagnosticable {
required this.bottomAppBarTheme,
required this.bottomNavigationBarTheme,
required this.bottomSheetTheme,
required this.buttonBarTheme,
required this.buttonTheme,
required this.cardTheme,
required this.checkboxTheme,
@ -735,7 +740,17 @@ class ThemeData with Diagnosticable {
required this.timePickerTheme,
required this.toggleButtonsTheme,
required this.tooltipTheme,
});
// DEPRECATED (newest deprecations at the bottom)
@Deprecated(
'Use OverflowBar instead. '
'This feature was deprecated after v3.21.0-10.0.pre.',
)
ButtonBarThemeData? buttonBarTheme,
}) : // DEPRECATED (newest deprecations at the bottom)
// should not be `required`, use getter pattern to avoid breakages.
_buttonBarTheme = buttonBarTheme,
// DEPRECATED (newest deprecations at the bottom)
assert(buttonBarTheme != null);
/// Create a [ThemeData] based on the colors in the given [colorScheme] and
/// text styles of the optional [textTheme].
@ -1248,9 +1263,6 @@ class ThemeData with Diagnosticable {
/// A theme for customizing the color, elevation, and shape of a bottom sheet.
final BottomSheetThemeData bottomSheetTheme;
/// A theme for customizing the appearance and layout of [ButtonBar] widgets.
final ButtonBarThemeData buttonBarTheme;
/// Defines the default configuration of button widgets, like [DropdownButton]
/// and [ButtonBar].
final ButtonThemeData buttonTheme;
@ -1390,6 +1402,14 @@ class ThemeData with Diagnosticable {
/// This is the value returned from [TooltipTheme.of].
final TooltipThemeData tooltipTheme;
/// A theme for customizing the appearance and layout of [ButtonBar] widgets.
@Deprecated(
'Use OverflowBar instead. '
'This feature was deprecated after v3.21.0-10.0.pre.',
)
ButtonBarThemeData get buttonBarTheme => _buttonBarTheme!;
final ButtonBarThemeData? _buttonBarTheme;
/// Creates a copy of this theme but with the given fields replaced with the new values.
///
/// The [brightness] value is applied to the [colorScheme].
@ -1449,7 +1469,6 @@ class ThemeData with Diagnosticable {
BottomAppBarTheme? bottomAppBarTheme,
BottomNavigationBarThemeData? bottomNavigationBarTheme,
BottomSheetThemeData? bottomSheetTheme,
ButtonBarThemeData? buttonBarTheme,
ButtonThemeData? buttonTheme,
CardTheme? cardTheme,
CheckboxThemeData? checkboxTheme,
@ -1497,6 +1516,11 @@ class ThemeData with Diagnosticable {
'This feature was deprecated after v3.13.0-0.2.pre.',
)
bool? useMaterial3,
@Deprecated(
'Use OverflowBar instead. '
'This feature was deprecated after v3.21.0-10.0.pre.',
)
ButtonBarThemeData? buttonBarTheme,
}) {
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
return ThemeData.raw(
@ -1554,7 +1578,6 @@ class ThemeData with Diagnosticable {
bottomAppBarTheme: bottomAppBarTheme ?? this.bottomAppBarTheme,
bottomNavigationBarTheme: bottomNavigationBarTheme ?? this.bottomNavigationBarTheme,
bottomSheetTheme: bottomSheetTheme ?? this.bottomSheetTheme,
buttonBarTheme: buttonBarTheme ?? this.buttonBarTheme,
buttonTheme: buttonTheme ?? this.buttonTheme,
cardTheme: cardTheme ?? this.cardTheme,
checkboxTheme: checkboxTheme ?? this.checkboxTheme,
@ -1593,6 +1616,7 @@ class ThemeData with Diagnosticable {
timePickerTheme: timePickerTheme ?? this.timePickerTheme,
toggleButtonsTheme: toggleButtonsTheme ?? this.toggleButtonsTheme,
tooltipTheme: tooltipTheme ?? this.tooltipTheme,
buttonBarTheme: buttonBarTheme ?? _buttonBarTheme,
);
}
@ -1747,7 +1771,6 @@ class ThemeData with Diagnosticable {
bottomAppBarTheme: BottomAppBarTheme.lerp(a.bottomAppBarTheme, b.bottomAppBarTheme, t),
bottomNavigationBarTheme: BottomNavigationBarThemeData.lerp(a.bottomNavigationBarTheme, b.bottomNavigationBarTheme, t),
bottomSheetTheme: BottomSheetThemeData.lerp(a.bottomSheetTheme, b.bottomSheetTheme, t)!,
buttonBarTheme: ButtonBarThemeData.lerp(a.buttonBarTheme, b.buttonBarTheme, t)!,
buttonTheme: t < 0.5 ? a.buttonTheme : b.buttonTheme,
cardTheme: CardTheme.lerp(a.cardTheme, b.cardTheme, t),
checkboxTheme: CheckboxThemeData.lerp(a.checkboxTheme, b.checkboxTheme, t),
@ -1786,6 +1809,7 @@ class ThemeData with Diagnosticable {
timePickerTheme: TimePickerThemeData.lerp(a.timePickerTheme, b.timePickerTheme, t),
toggleButtonsTheme: ToggleButtonsThemeData.lerp(a.toggleButtonsTheme, b.toggleButtonsTheme, t)!,
tooltipTheme: TooltipThemeData.lerp(a.tooltipTheme, b.tooltipTheme, t)!,
buttonBarTheme: ButtonBarThemeData.lerp(a.buttonBarTheme, b.buttonBarTheme, t),
);
}
@ -1847,7 +1871,6 @@ class ThemeData with Diagnosticable {
other.bottomAppBarTheme == bottomAppBarTheme &&
other.bottomNavigationBarTheme == bottomNavigationBarTheme &&
other.bottomSheetTheme == bottomSheetTheme &&
other.buttonBarTheme == buttonBarTheme &&
other.buttonTheme == buttonTheme &&
other.cardTheme == cardTheme &&
other.checkboxTheme == checkboxTheme &&
@ -1885,7 +1908,8 @@ class ThemeData with Diagnosticable {
other.textSelectionTheme == textSelectionTheme &&
other.timePickerTheme == timePickerTheme &&
other.toggleButtonsTheme == toggleButtonsTheme &&
other.tooltipTheme == tooltipTheme;
other.tooltipTheme == tooltipTheme &&
other.buttonBarTheme == buttonBarTheme;
}
@override
@ -1945,7 +1969,6 @@ class ThemeData with Diagnosticable {
bottomAppBarTheme,
bottomNavigationBarTheme,
bottomSheetTheme,
buttonBarTheme,
buttonTheme,
cardTheme,
checkboxTheme,
@ -1984,6 +2007,8 @@ class ThemeData with Diagnosticable {
timePickerTheme,
toggleButtonsTheme,
tooltipTheme,
// DEPRECATED (newest deprecations at the bottom)
buttonBarTheme,
];
return Object.hashAll(values);
}
@ -2044,7 +2069,6 @@ class ThemeData with Diagnosticable {
properties.add(DiagnosticsProperty<BottomAppBarTheme>('bottomAppBarTheme', bottomAppBarTheme, defaultValue: defaultData.bottomAppBarTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<BottomNavigationBarThemeData>('bottomNavigationBarTheme', bottomNavigationBarTheme, defaultValue: defaultData.bottomNavigationBarTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<BottomSheetThemeData>('bottomSheetTheme', bottomSheetTheme, defaultValue: defaultData.bottomSheetTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<ButtonBarThemeData>('buttonBarTheme', buttonBarTheme, defaultValue: defaultData.buttonBarTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<ButtonThemeData>('buttonTheme', buttonTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<CardTheme>('cardTheme', cardTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<CheckboxThemeData>('checkboxTheme', checkboxTheme, defaultValue: defaultData.checkboxTheme, level: DiagnosticLevel.debug));
@ -2083,6 +2107,8 @@ class ThemeData with Diagnosticable {
properties.add(DiagnosticsProperty<TimePickerThemeData>('timePickerTheme', timePickerTheme, defaultValue: defaultData.timePickerTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<ToggleButtonsThemeData>('toggleButtonsTheme', toggleButtonsTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<TooltipThemeData>('tooltipTheme', tooltipTheme, level: DiagnosticLevel.debug));
// DEPRECATED (newest deprecations at the bottom)
properties.add(DiagnosticsProperty<ButtonBarThemeData>('buttonBarTheme', buttonBarTheme, defaultValue: defaultData.buttonBarTheme, level: DiagnosticLevel.debug));
}
}

View File

@ -0,0 +1,14 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
void main() {
// Changes made in https://github.com/flutter/flutter/pull/145523
ButtonBar();
// Changes made in https://github.com/flutter/flutter/pull/145523
ThemeData theme = ThemeData();
theme = ThemeData(buttonBarTheme: ButtonBarThemeData());
}

View File

@ -0,0 +1,14 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
void main() {
// Changes made in https://github.com/flutter/flutter/pull/145523
OverflowBar();
// Changes made in https://github.com/flutter/flutter/pull/145523
ThemeData theme = ThemeData();
theme = ThemeData();
}