From 17e2fce1cfb6d23c5676d3f7889f1eb779ac548b Mon Sep 17 00:00:00 2001 From: Darren Austin Date: Thu, 19 May 2022 09:35:33 -0700 Subject: [PATCH] Add const `MaterialStatePropertyAll` class. (#104127) --- .../gen_defaults/lib/button_template.dart | 2 +- .../navigation_bar/navigation_bar.0.dart | 2 +- .../api/lib/widgets/actions/actions.0.dart | 2 +- .../lib/src/material/button_style.dart | 2 +- .../lib/src/material/button_style_button.dart | 4 +- .../lib/src/material/elevated_button.dart | 6 +- .../lib/src/material/material_state.dart | 20 ++++- .../lib/src/material/navigation_bar.dart | 4 +- .../lib/src/material/outlined_button.dart | 2 +- .../flutter/lib/src/material/stepper.dart | 4 +- .../flutter/lib/src/material/text_button.dart | 4 +- .../lib/src/material/toggle_buttons.dart | 18 ++-- .../test/material/button_style_test.dart | 90 +++++++++---------- .../flutter/test/material/checkbox_test.dart | 2 +- .../test/material/checkbox_theme_test.dart | 36 ++++---- .../test/material/data_table_test.dart | 6 +- .../test/material/data_table_theme_test.dart | 28 +++--- .../test/material/elevated_button_test.dart | 14 +-- .../material_state_property_test.dart | 12 +++ .../material/navigation_bar_theme_test.dart | 16 ++-- .../test/material/outlined_button_test.dart | 12 +-- .../flutter/test/material/radio_test.dart | 2 +- .../test/material/radio_theme_test.dart | 26 +++--- .../test/material/slider_theme_test.dart | 2 +- .../flutter/test/material/switch_test.dart | 2 +- .../test/material/switch_theme_test.dart | 34 +++---- .../test/material/text_button_test.dart | 4 +- 27 files changed, 190 insertions(+), 166 deletions(-) diff --git a/dev/tools/gen_defaults/lib/button_template.dart b/dev/tools/gen_defaults/lib/button_template.dart index 381087194a..98e811c453 100644 --- a/dev/tools/gen_defaults/lib/button_template.dart +++ b/dev/tools/gen_defaults/lib/button_template.dart @@ -64,7 +64,7 @@ class _TokenDefaultsM3 extends ButtonStyle { @override MaterialStateProperty get textStyle => - MaterialStateProperty.all(${textStyle("$tokenGroup.label-text")}); + MaterialStatePropertyAll(${textStyle("$tokenGroup.label-text")}); @override MaterialStateProperty? get backgroundColor =>${_backgroundColor()}; diff --git a/examples/api/lib/material/navigation_bar/navigation_bar.0.dart b/examples/api/lib/material/navigation_bar/navigation_bar.0.dart index 2b0ac12519..12506fc1d4 100644 --- a/examples/api/lib/material/navigation_bar/navigation_bar.0.dart +++ b/examples/api/lib/material/navigation_bar/navigation_bar.0.dart @@ -143,7 +143,7 @@ class ListPage extends StatelessWidget { padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 8), child: OutlinedButton( style: buttonStyle.copyWith( - backgroundColor: MaterialStateProperty.all( + backgroundColor: MaterialStatePropertyAll( Color.lerp(destination.color[100], Colors.white, index / itemCount)! ), ), diff --git a/examples/api/lib/widgets/actions/actions.0.dart b/examples/api/lib/widgets/actions/actions.0.dart index d088fb56f2..34636f3268 100644 --- a/examples/api/lib/widgets/actions/actions.0.dart +++ b/examples/api/lib/widgets/actions/actions.0.dart @@ -101,7 +101,7 @@ class _SaveButtonState extends State { icon: const Icon(Icons.save), label: Text('$savedValue'), style: ButtonStyle( - foregroundColor: MaterialStateProperty.all( + foregroundColor: MaterialStatePropertyAll( widget.valueNotifier.value ? Colors.red : Colors.green, ), ), diff --git a/packages/flutter/lib/src/material/button_style.dart b/packages/flutter/lib/src/material/button_style.dart index 4026fd7ed6..f9b38983ff 100644 --- a/packages/flutter/lib/src/material/button_style.dart +++ b/packages/flutter/lib/src/material/button_style.dart @@ -53,7 +53,7 @@ import 'theme_data.dart'; /// ```dart /// ElevatedButton( /// style: ButtonStyle( -/// backgroundColor: MaterialStateProperty.all(Colors.green), +/// backgroundColor: MaterialStatePropertyAll(Colors.green), /// ), /// ) /// ``` diff --git a/packages/flutter/lib/src/material/button_style_button.dart b/packages/flutter/lib/src/material/button_style_button.dart index ddb6e3f4ae..7cc021538d 100644 --- a/packages/flutter/lib/src/material/button_style_button.dart +++ b/packages/flutter/lib/src/material/button_style_button.dart @@ -148,10 +148,10 @@ abstract class ButtonStyleButton extends StatefulWidget { properties.add(DiagnosticsProperty('focusNode', focusNode, defaultValue: null)); } - /// Returns null if [value] is null, otherwise `MaterialStateProperty.all(value)`. + /// Returns null if [value] is null, otherwise `MaterialStatePropertyAll(value)`. /// /// A convenience method for subclasses. - static MaterialStateProperty? allOrNull(T? value) => value == null ? null : MaterialStateProperty.all(value); + static MaterialStateProperty? allOrNull(T? value) => value == null ? null : MaterialStatePropertyAll(value); /// Returns an interpolated value based on the [textScaleFactor] parameter: /// diff --git a/packages/flutter/lib/src/material/elevated_button.dart b/packages/flutter/lib/src/material/elevated_button.dart index 59f0e61ec5..6b42d930f9 100644 --- a/packages/flutter/lib/src/material/elevated_button.dart +++ b/packages/flutter/lib/src/material/elevated_button.dart @@ -172,7 +172,7 @@ class ElevatedButton extends ButtonStyleButton { : _ElevatedButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor); return ButtonStyle( - textStyle: MaterialStateProperty.all(textStyle), + textStyle: MaterialStatePropertyAll(textStyle), backgroundColor: backgroundColor, foregroundColor: foregroundColor, overlayColor: overlayColor, @@ -468,7 +468,7 @@ class _ElevatedButtonWithIcon extends ElevatedButton { MediaQuery.maybeOf(context)?.textScaleFactor ?? 1, ); return super.defaultStyleOf(context).copyWith( - padding: MaterialStateProperty.all(scaledPadding), + padding: MaterialStatePropertyAll(scaledPadding), ); } } @@ -510,7 +510,7 @@ class _TokenDefaultsM3 extends ButtonStyle { @override MaterialStateProperty get textStyle => - MaterialStateProperty.all(Theme.of(context).textTheme.labelLarge); + MaterialStatePropertyAll(Theme.of(context).textTheme.labelLarge); @override MaterialStateProperty? get backgroundColor => diff --git a/packages/flutter/lib/src/material/material_state.dart b/packages/flutter/lib/src/material/material_state.dart index a67758b8ff..282dc561ce 100644 --- a/packages/flutter/lib/src/material/material_state.dart +++ b/packages/flutter/lib/src/material/material_state.dart @@ -651,7 +651,13 @@ abstract class MaterialStateProperty { /// Convenience method for creating a [MaterialStateProperty] that resolves /// to a single value for all states. - static MaterialStateProperty all(T value) => _MaterialStatePropertyAll(value); + /// + /// If you need a const value, use [MaterialStatePropertyAll] directly. + /// + // TODO(darrenaustin): Deprecate this when we have the ability to create + // a dart fix that will replace this with MaterialStatePropertyAll: + // https://github.com/dart-lang/sdk/issues/49056. + static MaterialStateProperty all(T value) => MaterialStatePropertyAll(value); } class _MaterialStatePropertyWith implements MaterialStateProperty { @@ -663,14 +669,20 @@ class _MaterialStatePropertyWith implements MaterialStateProperty { T resolve(Set states) => _resolve(states); } -class _MaterialStatePropertyAll implements MaterialStateProperty { - _MaterialStatePropertyAll(this.value); +/// Convenience class for creating a [MaterialStateProperty] that +/// resolves to the given value for all states. +class MaterialStatePropertyAll implements MaterialStateProperty { + /// Constructs a [MaterialStateProperty] that always resolves to the given + /// value. + const MaterialStatePropertyAll(this.value); + + /// The value of the property that will be used for all states. final T value; @override T resolve(Set states) => value; @override - String toString() => 'MaterialStateProperty.all($value)'; + String toString() => 'MaterialStatePropertyAll($value)'; } diff --git a/packages/flutter/lib/src/material/navigation_bar.dart b/packages/flutter/lib/src/material/navigation_bar.dart index f625524404..f695205573 100644 --- a/packages/flutter/lib/src/material/navigation_bar.dart +++ b/packages/flutter/lib/src/material/navigation_bar.dart @@ -1194,7 +1194,7 @@ class _Defaults extends NavigationBarThemeData { @override Color? get backgroundColor => ElevationOverlay.colorWithOverlay(_colors.surface, _colors.onSurface, 3.0); @override MaterialStateProperty? get iconTheme { - return MaterialStateProperty.all(IconThemeData( + return MaterialStatePropertyAll(IconThemeData( size: 24, color: _colors.onSurface, )); @@ -1202,7 +1202,7 @@ class _Defaults extends NavigationBarThemeData { @override Color? get indicatorColor => _colors.secondary.withOpacity(0.24); - @override MaterialStateProperty? get labelTextStyle => MaterialStateProperty.all(_theme.textTheme.overline!.copyWith(color: _colors.onSurface)); + @override MaterialStateProperty? get labelTextStyle => MaterialStatePropertyAll(_theme.textTheme.overline!.copyWith(color: _colors.onSurface)); } // BEGIN GENERATED TOKEN PROPERTIES diff --git a/packages/flutter/lib/src/material/outlined_button.dart b/packages/flutter/lib/src/material/outlined_button.dart index 6cfe6d316a..78681b41c2 100644 --- a/packages/flutter/lib/src/material/outlined_button.dart +++ b/packages/flutter/lib/src/material/outlined_button.dart @@ -433,7 +433,7 @@ class _TokenDefaultsM3 extends ButtonStyle { @override MaterialStateProperty get textStyle => - MaterialStateProperty.all(Theme.of(context).textTheme.labelLarge); + MaterialStatePropertyAll(Theme.of(context).textTheme.labelLarge); @override MaterialStateProperty? get backgroundColor => diff --git a/packages/flutter/lib/src/material/stepper.dart b/packages/flutter/lib/src/material/stepper.dart index b7065d7046..c9b62224ad 100644 --- a/packages/flutter/lib/src/material/stepper.dart +++ b/packages/flutter/lib/src/material/stepper.dart @@ -504,8 +504,8 @@ class _StepperState extends State with TickerProviderStateMixin { backgroundColor: MaterialStateProperty.resolveWith((Set states) { return _isDark() || states.contains(MaterialState.disabled) ? null : colorScheme.primary; }), - padding: MaterialStateProperty.all(buttonPadding), - shape: MaterialStateProperty.all(buttonShape), + padding: const MaterialStatePropertyAll(buttonPadding), + shape: const MaterialStatePropertyAll(buttonShape), ), child: Text(localizations.continueButtonLabel), ), diff --git a/packages/flutter/lib/src/material/text_button.dart b/packages/flutter/lib/src/material/text_button.dart index 3f68aed531..918cddd2a3 100644 --- a/packages/flutter/lib/src/material/text_button.dart +++ b/packages/flutter/lib/src/material/text_button.dart @@ -426,7 +426,7 @@ class _TextButtonWithIcon extends TextButton { MediaQuery.maybeOf(context)?.textScaleFactor ?? 1, ); return super.defaultStyleOf(context).copyWith( - padding: MaterialStateProperty.all(scaledPadding), + padding: MaterialStatePropertyAll(scaledPadding), ); } } @@ -471,7 +471,7 @@ class _TokenDefaultsM3 extends ButtonStyle { @override MaterialStateProperty get textStyle => - MaterialStateProperty.all(Theme.of(context).textTheme.labelLarge); + MaterialStatePropertyAll(Theme.of(context).textTheme.labelLarge); @override MaterialStateProperty? get backgroundColor => diff --git a/packages/flutter/lib/src/material/toggle_buttons.dart b/packages/flutter/lib/src/material/toggle_buttons.dart index be0f8cdd80..be57bd2069 100644 --- a/packages/flutter/lib/src/material/toggle_buttons.dart +++ b/packages/flutter/lib/src/material/toggle_buttons.dart @@ -742,8 +742,8 @@ class ToggleButtons extends StatelessWidget { child: TextButton( focusNode: focusNodes != null ? focusNodes![index] : null, style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(effectiveFillColor), - foregroundColor: MaterialStateProperty.all(currentColor), + backgroundColor: MaterialStatePropertyAll(effectiveFillColor), + foregroundColor: MaterialStatePropertyAll(currentColor), overlayColor: _ToggleButtonDefaultOverlay( selected: onPressed != null && isSelected[index], unselected: onPressed != null && !isSelected[index], @@ -754,15 +754,15 @@ class ToggleButtons extends StatelessWidget { hoverColor: hoverColor ?? toggleButtonsTheme.hoverColor, splashColor: splashColor ?? toggleButtonsTheme.splashColor, ), - elevation: MaterialStateProperty.all(0), - textStyle: MaterialStateProperty.all(currentTextStyle.copyWith( + elevation: const MaterialStatePropertyAll(0), + textStyle: MaterialStatePropertyAll(currentTextStyle.copyWith( color: currentColor, )), - padding: MaterialStateProperty.all(EdgeInsets.zero), - minimumSize: MaterialStateProperty.all(minimumSize), - maximumSize: MaterialStateProperty.all(maximumSize), - shape: MaterialStateProperty.all(const RoundedRectangleBorder()), - mouseCursor: MaterialStateProperty.all(mouseCursor), + padding: const MaterialStatePropertyAll(EdgeInsets.zero), + minimumSize: MaterialStatePropertyAll(minimumSize), + maximumSize: MaterialStatePropertyAll(maximumSize), + shape: const MaterialStatePropertyAll(RoundedRectangleBorder()), + mouseCursor: MaterialStatePropertyAll(mouseCursor), visualDensity: VisualDensity.standard, tapTargetSize: MaterialTapTargetSize.shrinkWrap, animationDuration: kThemeChangeDuration, diff --git a/packages/flutter/test/material/button_style_test.dart b/packages/flutter/test/material/button_style_test.dart index 32afc9bb4f..0bd0baa6f8 100644 --- a/packages/flutter/test/material/button_style_test.dart +++ b/packages/flutter/test/material/button_style_test.dart @@ -50,22 +50,22 @@ void main() { testWidgets('ButtonStyle debugFillProperties', (WidgetTester tester) async { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); - ButtonStyle( - textStyle: MaterialStateProperty.all(const TextStyle(fontSize: 10.0)), - backgroundColor: MaterialStateProperty.all(const Color(0xfffffff1)), - foregroundColor: MaterialStateProperty.all(const Color(0xfffffff2)), - overlayColor: MaterialStateProperty.all(const Color(0xfffffff3)), - shadowColor: MaterialStateProperty.all(const Color(0xfffffff4)), - surfaceTintColor: MaterialStateProperty.all(const Color(0xfffffff5)), - elevation: MaterialStateProperty.all(1.5), - padding: MaterialStateProperty.all(const EdgeInsets.all(1.0)), - minimumSize: MaterialStateProperty.all(const Size(1.0, 2.0)), - side: MaterialStateProperty.all(const BorderSide(width: 4.0, color: Color(0xfffffff6))), - maximumSize: MaterialStateProperty.all(const Size(100.0, 200.0)), - shape: MaterialStateProperty.all(const StadiumBorder()), - mouseCursor: MaterialStateProperty.all(SystemMouseCursors.forbidden), + const ButtonStyle( + textStyle: MaterialStatePropertyAll(TextStyle(fontSize: 10.0)), + backgroundColor: MaterialStatePropertyAll(Color(0xfffffff1)), + foregroundColor: MaterialStatePropertyAll(Color(0xfffffff2)), + overlayColor: MaterialStatePropertyAll(Color(0xfffffff3)), + shadowColor: MaterialStatePropertyAll(Color(0xfffffff4)), + surfaceTintColor: MaterialStatePropertyAll(Color(0xfffffff5)), + elevation: MaterialStatePropertyAll(1.5), + padding: MaterialStatePropertyAll(EdgeInsets.all(1.0)), + minimumSize: MaterialStatePropertyAll(Size(1.0, 2.0)), + side: MaterialStatePropertyAll(BorderSide(width: 4.0, color: Color(0xfffffff6))), + maximumSize: MaterialStatePropertyAll(Size(100.0, 200.0)), + shape: MaterialStatePropertyAll(StadiumBorder()), + mouseCursor: MaterialStatePropertyAll(SystemMouseCursors.forbidden), tapTargetSize: MaterialTapTargetSize.shrinkWrap, - animationDuration: const Duration(seconds: 1), + animationDuration: Duration(seconds: 1), enableFeedback: true, ).debugFillProperties(builder); @@ -75,19 +75,19 @@ void main() { .toList(); expect(description, [ - 'textStyle: MaterialStateProperty.all(TextStyle(inherit: true, size: 10.0))', - 'backgroundColor: MaterialStateProperty.all(Color(0xfffffff1))', - 'foregroundColor: MaterialStateProperty.all(Color(0xfffffff2))', - 'overlayColor: MaterialStateProperty.all(Color(0xfffffff3))', - 'shadowColor: MaterialStateProperty.all(Color(0xfffffff4))', - 'surfaceTintColor: MaterialStateProperty.all(Color(0xfffffff5))', - 'elevation: MaterialStateProperty.all(1.5)', - 'padding: MaterialStateProperty.all(EdgeInsets.all(1.0))', - 'minimumSize: MaterialStateProperty.all(Size(1.0, 2.0))', - 'maximumSize: MaterialStateProperty.all(Size(100.0, 200.0))', - 'side: MaterialStateProperty.all(BorderSide(Color(0xfffffff6), 4.0, BorderStyle.solid))', - 'shape: MaterialStateProperty.all(StadiumBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none)))', - 'mouseCursor: MaterialStateProperty.all(SystemMouseCursor(forbidden))', + 'textStyle: MaterialStatePropertyAll(TextStyle(inherit: true, size: 10.0))', + 'backgroundColor: MaterialStatePropertyAll(Color(0xfffffff1))', + 'foregroundColor: MaterialStatePropertyAll(Color(0xfffffff2))', + 'overlayColor: MaterialStatePropertyAll(Color(0xfffffff3))', + 'shadowColor: MaterialStatePropertyAll(Color(0xfffffff4))', + 'surfaceTintColor: MaterialStatePropertyAll(Color(0xfffffff5))', + 'elevation: MaterialStatePropertyAll(1.5)', + 'padding: MaterialStatePropertyAll(EdgeInsets.all(1.0))', + 'minimumSize: MaterialStatePropertyAll(Size(1.0, 2.0))', + 'maximumSize: MaterialStatePropertyAll(Size(100.0, 200.0))', + 'side: MaterialStatePropertyAll(BorderSide(Color(0xfffffff6), 4.0, BorderStyle.solid))', + 'shape: MaterialStatePropertyAll(StadiumBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none)))', + 'mouseCursor: MaterialStatePropertyAll(SystemMouseCursor(forbidden))', 'tapTargetSize: shrinkWrap', 'animationDuration: 0:00:01.000000', 'enableFeedback: true', @@ -95,26 +95,26 @@ void main() { }); testWidgets('ButtonStyle copyWith, merge', (WidgetTester tester) async { - final MaterialStateProperty textStyle = MaterialStateProperty.all(const TextStyle(fontSize: 10)); - final MaterialStateProperty backgroundColor = MaterialStateProperty.all(const Color(0xfffffff1)); - final MaterialStateProperty foregroundColor = MaterialStateProperty.all(const Color(0xfffffff2)); - final MaterialStateProperty overlayColor = MaterialStateProperty.all(const Color(0xfffffff3)); - final MaterialStateProperty shadowColor = MaterialStateProperty.all(const Color(0xfffffff4)); - final MaterialStateProperty surfaceTintColor = MaterialStateProperty.all(const Color(0xfffffff5)); - final MaterialStateProperty elevation = MaterialStateProperty.all(1); - final MaterialStateProperty padding = MaterialStateProperty.all(const EdgeInsets.all(1)); - final MaterialStateProperty minimumSize = MaterialStateProperty.all(const Size(1, 2)); - final MaterialStateProperty fixedSize = MaterialStateProperty.all(const Size(3, 4)); - final MaterialStateProperty maximumSize = MaterialStateProperty.all(const Size(5, 6)); - final MaterialStateProperty side = MaterialStateProperty.all(const BorderSide()); - final MaterialStateProperty shape = MaterialStateProperty.all(const StadiumBorder()); - final MaterialStateProperty mouseCursor = MaterialStateProperty.all(SystemMouseCursors.forbidden); + const MaterialStateProperty textStyle = MaterialStatePropertyAll(TextStyle(fontSize: 10)); + const MaterialStateProperty backgroundColor = MaterialStatePropertyAll(Color(0xfffffff1)); + const MaterialStateProperty foregroundColor = MaterialStatePropertyAll(Color(0xfffffff2)); + const MaterialStateProperty overlayColor = MaterialStatePropertyAll(Color(0xfffffff3)); + const MaterialStateProperty shadowColor = MaterialStatePropertyAll(Color(0xfffffff4)); + const MaterialStateProperty surfaceTintColor = MaterialStatePropertyAll(Color(0xfffffff5)); + const MaterialStateProperty elevation = MaterialStatePropertyAll(1); + const MaterialStateProperty padding = MaterialStatePropertyAll(EdgeInsets.all(1)); + const MaterialStateProperty minimumSize = MaterialStatePropertyAll(Size(1, 2)); + const MaterialStateProperty fixedSize = MaterialStatePropertyAll(Size(3, 4)); + const MaterialStateProperty maximumSize = MaterialStatePropertyAll(Size(5, 6)); + const MaterialStateProperty side = MaterialStatePropertyAll(BorderSide()); + const MaterialStateProperty shape = MaterialStatePropertyAll(StadiumBorder()); + const MaterialStateProperty mouseCursor = MaterialStatePropertyAll(SystemMouseCursors.forbidden); const VisualDensity visualDensity = VisualDensity.compact; const MaterialTapTargetSize tapTargetSize = MaterialTapTargetSize.shrinkWrap; const Duration animationDuration = Duration(seconds: 1); const bool enableFeedback = true; - final ButtonStyle style = ButtonStyle( + const ButtonStyle style = ButtonStyle( textStyle: textStyle, backgroundColor: backgroundColor, foregroundColor: foregroundColor, @@ -180,8 +180,8 @@ void main() { const BorderSide whiteSide = BorderSide(color: Color(0xFFFFFFFF)); const BorderSide emptyBlackSide = BorderSide(width: 0, color: Color(0x00000000)); - final ButtonStyle blackStyle = ButtonStyle(side: MaterialStateProperty.all(blackSide)); - final ButtonStyle whiteStyle = ButtonStyle(side: MaterialStateProperty.all(whiteSide)); + const ButtonStyle blackStyle = ButtonStyle(side: MaterialStatePropertyAll(blackSide)); + const ButtonStyle whiteStyle = ButtonStyle(side: MaterialStatePropertyAll(whiteSide)); // MaterialState.all(value) properties resolve to value // for any set of MaterialStates. diff --git a/packages/flutter/test/material/checkbox_test.dart b/packages/flutter/test/material/checkbox_test.dart index 516dd02bfb..f9b8c63c27 100644 --- a/packages/flutter/test/material/checkbox_test.dart +++ b/packages/flutter/test/material/checkbox_test.dart @@ -968,7 +968,7 @@ void main() { autofocus: focused, value: active, onChanged: (_) { }, - fillColor: MaterialStateProperty.all(fillColor), + fillColor: const MaterialStatePropertyAll(fillColor), overlayColor: useOverlay ? MaterialStateProperty.resolveWith(getOverlayColor) : null, hoverColor: hoverColor, focusColor: focusColor, diff --git a/packages/flutter/test/material/checkbox_theme_test.dart b/packages/flutter/test/material/checkbox_theme_test.dart index d7468392a0..c180dacc15 100644 --- a/packages/flutter/test/material/checkbox_theme_test.dart +++ b/packages/flutter/test/material/checkbox_theme_test.dart @@ -49,11 +49,11 @@ void main() { testWidgets('CheckboxThemeData implements debugFillProperties', (WidgetTester tester) async { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); - CheckboxThemeData( - mouseCursor: MaterialStateProperty.all(SystemMouseCursors.click), - fillColor: MaterialStateProperty.all(const Color(0xfffffff0)), - checkColor: MaterialStateProperty.all(const Color(0xfffffff1)), - overlayColor: MaterialStateProperty.all(const Color(0xfffffff2)), + const CheckboxThemeData( + mouseCursor: MaterialStatePropertyAll(SystemMouseCursors.click), + fillColor: MaterialStatePropertyAll(Color(0xfffffff0)), + checkColor: MaterialStatePropertyAll(Color(0xfffffff1)), + overlayColor: MaterialStatePropertyAll(Color(0xfffffff2)), splashRadius: 1.0, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, visualDensity: VisualDensity.standard, @@ -64,10 +64,10 @@ void main() { .map((DiagnosticsNode node) => node.toString()) .toList(); - expect(description[0], 'mouseCursor: MaterialStateProperty.all(SystemMouseCursor(click))'); - expect(description[1], 'fillColor: MaterialStateProperty.all(Color(0xfffffff0))'); - expect(description[2], 'checkColor: MaterialStateProperty.all(Color(0xfffffff1))'); - expect(description[3], 'overlayColor: MaterialStateProperty.all(Color(0xfffffff2))'); + expect(description[0], 'mouseCursor: MaterialStatePropertyAll(SystemMouseCursor(click))'); + expect(description[1], 'fillColor: MaterialStatePropertyAll(Color(0xfffffff0))'); + expect(description[2], 'checkColor: MaterialStatePropertyAll(Color(0xfffffff1))'); + expect(description[3], 'overlayColor: MaterialStatePropertyAll(Color(0xfffffff2))'); expect(description[4], 'splashRadius: 1.0'); expect(description[5], 'materialTapTargetSize: MaterialTapTargetSize.shrinkWrap'); expect(description[6], equalsIgnoringHashCodes('visualDensity: VisualDensity#00000(h: 0.0, v: 0.0)')); @@ -91,7 +91,7 @@ void main() { return MaterialApp( theme: ThemeData( checkboxTheme: CheckboxThemeData( - mouseCursor: MaterialStateProperty.all(mouseCursor), + mouseCursor: const MaterialStatePropertyAll(mouseCursor), fillColor: MaterialStateProperty.resolveWith((Set states) { if (states.contains(MaterialState.selected)) { return selectedFillColor; @@ -182,14 +182,14 @@ void main() { return MaterialApp( theme: ThemeData( checkboxTheme: CheckboxThemeData( - mouseCursor: MaterialStateProperty.all(themeMouseCursor), + mouseCursor: const MaterialStatePropertyAll(themeMouseCursor), fillColor: MaterialStateProperty.resolveWith((Set states) { if (states.contains(MaterialState.selected)) { return themeSelectedFillColor; } return themeDefaultFillColor; }), - checkColor: MaterialStateProperty.all(themeCheckColor), + checkColor: const MaterialStatePropertyAll(themeCheckColor), overlayColor: MaterialStateProperty.resolveWith((Set states) { if (states.contains(MaterialState.focused)) { return themeFocusOverlayColor; @@ -361,16 +361,16 @@ void main() { Widget buildCheckbox({required bool active}) { return MaterialApp( theme: ThemeData( - checkboxTheme: CheckboxThemeData( - checkColor: MaterialStateProperty.all(globalThemeCheckColor), - fillColor: MaterialStateProperty.all(globalThemeFillColor), + checkboxTheme: const CheckboxThemeData( + checkColor: MaterialStatePropertyAll(globalThemeCheckColor), + fillColor: MaterialStatePropertyAll(globalThemeFillColor), ), ), home: Scaffold( body: CheckboxTheme( - data: CheckboxThemeData( - fillColor: MaterialStateProperty.all(localThemeFillColor), - checkColor: MaterialStateProperty.all(localThemeCheckColor), + data: const CheckboxThemeData( + fillColor: MaterialStatePropertyAll(localThemeFillColor), + checkColor: MaterialStatePropertyAll(localThemeCheckColor), ), child: Checkbox( value: active, diff --git a/packages/flutter/test/material/data_table_test.dart b/packages/flutter/test/material/data_table_test.dart index 182d043065..5ff212e39d 100644 --- a/packages/flutter/test/material/data_table_test.dart +++ b/packages/flutter/test/material/data_table_test.dart @@ -1412,9 +1412,9 @@ void main() { const Color checkColor = Color(0xFF0000FF); final ThemeData themeData = ThemeData( - checkboxTheme: CheckboxThemeData( - fillColor: MaterialStateProperty.all(fillColor), - checkColor: MaterialStateProperty.all(checkColor), + checkboxTheme: const CheckboxThemeData( + fillColor: MaterialStatePropertyAll(fillColor), + checkColor: MaterialStatePropertyAll(checkColor), ), ); Widget buildTable() { diff --git a/packages/flutter/test/material/data_table_theme_test.dart b/packages/flutter/test/material/data_table_theme_test.dart index fa83cdd778..fb62a7ae5e 100644 --- a/packages/flutter/test/material/data_table_theme_test.dart +++ b/packages/flutter/test/material/data_table_theme_test.dart @@ -92,10 +92,10 @@ void main() { testWidgets('DataTable is themeable', (WidgetTester tester) async { const BoxDecoration decoration = BoxDecoration(color: Color(0xfffffff0)); - final MaterialStateProperty dataRowColor = MaterialStateProperty.all(const Color(0xfffffff1)); + const MaterialStateProperty dataRowColor = MaterialStatePropertyAll(Color(0xfffffff1)); const double dataRowHeight = 51.0; const TextStyle dataTextStyle = TextStyle(fontSize: 12.5); - final MaterialStateProperty headingRowColor = MaterialStateProperty.all(const Color(0xfffffff2)); + const MaterialStateProperty headingRowColor = MaterialStatePropertyAll(Color(0xfffffff2)); const double headingRowHeight = 52.0; const TextStyle headingTextStyle = TextStyle(fontSize: 14.5); const double horizontalMargin = 3.0; @@ -105,7 +105,7 @@ void main() { await tester.pumpWidget( MaterialApp( theme: ThemeData( - dataTableTheme: DataTableThemeData( + dataTableTheme: const DataTableThemeData( decoration: decoration, dataRowColor: dataRowColor, dataRowHeight: dataRowHeight, @@ -159,10 +159,10 @@ void main() { testWidgets('DataTable properties are taken over the theme values', (WidgetTester tester) async { const BoxDecoration themeDecoration = BoxDecoration(color: Color(0xfffffff1)); - final MaterialStateProperty themeDataRowColor = MaterialStateProperty.all(const Color(0xfffffff0)); + const MaterialStateProperty themeDataRowColor = MaterialStatePropertyAll(Color(0xfffffff0)); const double themeDataRowHeight = 50.0; const TextStyle themeDataTextStyle = TextStyle(fontSize: 11.5); - final MaterialStateProperty themeHeadingRowColor = MaterialStateProperty.all(const Color(0xfffffff1)); + const MaterialStateProperty themeHeadingRowColor = MaterialStatePropertyAll(Color(0xfffffff1)); const double themeHeadingRowHeight = 51.0; const TextStyle themeHeadingTextStyle = TextStyle(fontSize: 13.5); const double themeHorizontalMargin = 2.0; @@ -170,10 +170,10 @@ void main() { const double themeDividerThickness = 4.0; const BoxDecoration decoration = BoxDecoration(color: Color(0xfffffff0)); - final MaterialStateProperty dataRowColor = MaterialStateProperty.all(const Color(0xfffffff1)); + const MaterialStateProperty dataRowColor = MaterialStatePropertyAll(Color(0xfffffff1)); const double dataRowHeight = 51.0; const TextStyle dataTextStyle = TextStyle(fontSize: 12.5); - final MaterialStateProperty headingRowColor = MaterialStateProperty.all(const Color(0xfffffff2)); + const MaterialStateProperty headingRowColor = MaterialStatePropertyAll(Color(0xfffffff2)); const double headingRowHeight = 52.0; const TextStyle headingTextStyle = TextStyle(fontSize: 14.5); const double horizontalMargin = 3.0; @@ -182,7 +182,7 @@ void main() { await tester.pumpWidget( MaterialApp( theme: ThemeData( - dataTableTheme: DataTableThemeData( + dataTableTheme: const DataTableThemeData( decoration: themeDecoration, dataRowColor: themeDataRowColor, dataRowHeight: themeDataRowHeight, @@ -246,10 +246,10 @@ void main() { testWidgets('Local DataTableTheme can override global DataTableTheme', (WidgetTester tester) async { const BoxDecoration globalThemeDecoration = BoxDecoration(color: Color(0xfffffff1)); - final MaterialStateProperty globalThemeDataRowColor = MaterialStateProperty.all(const Color(0xfffffff0)); + const MaterialStateProperty globalThemeDataRowColor = MaterialStatePropertyAll(Color(0xfffffff0)); const double globalThemeDataRowHeight = 50.0; const TextStyle globalThemeDataTextStyle = TextStyle(fontSize: 11.5); - final MaterialStateProperty globalThemeHeadingRowColor = MaterialStateProperty.all(const Color(0xfffffff1)); + const MaterialStateProperty globalThemeHeadingRowColor = MaterialStatePropertyAll(Color(0xfffffff1)); const double globalThemeHeadingRowHeight = 51.0; const TextStyle globalThemeHeadingTextStyle = TextStyle(fontSize: 13.5); const double globalThemeHorizontalMargin = 2.0; @@ -257,10 +257,10 @@ void main() { const double globalThemeDividerThickness = 4.0; const BoxDecoration localThemeDecoration = BoxDecoration(color: Color(0xfffffff0)); - final MaterialStateProperty localThemeDataRowColor = MaterialStateProperty.all(const Color(0xfffffff1)); + const MaterialStateProperty localThemeDataRowColor = MaterialStatePropertyAll(Color(0xfffffff1)); const double localThemeDataRowHeight = 51.0; const TextStyle localThemeDataTextStyle = TextStyle(fontSize: 12.5); - final MaterialStateProperty localThemeHeadingRowColor = MaterialStateProperty.all(const Color(0xfffffff2)); + const MaterialStateProperty localThemeHeadingRowColor = MaterialStatePropertyAll(Color(0xfffffff2)); const double localThemeHeadingRowHeight = 52.0; const TextStyle localThemeHeadingTextStyle = TextStyle(fontSize: 14.5); const double localThemeHorizontalMargin = 3.0; @@ -270,7 +270,7 @@ void main() { await tester.pumpWidget( MaterialApp( theme: ThemeData( - dataTableTheme: DataTableThemeData( + dataTableTheme: const DataTableThemeData( decoration: globalThemeDecoration, dataRowColor: globalThemeDataRowColor, dataRowHeight: globalThemeDataRowHeight, @@ -285,7 +285,7 @@ void main() { ), home: Scaffold( body: DataTableTheme( - data: DataTableThemeData( + data: const DataTableThemeData( decoration: localThemeDecoration, dataRowColor: localThemeDataRowColor, dataRowHeight: localThemeDataRowHeight, diff --git a/packages/flutter/test/material/elevated_button_test.dart b/packages/flutter/test/material/elevated_button_test.dart index 3478826985..af6e678045 100644 --- a/packages/flutter/test/material/elevated_button_test.dart +++ b/packages/flutter/test/material/elevated_button_test.dart @@ -689,11 +689,11 @@ void main() { textDirection: TextDirection.ltr, child: Center( child: ElevatedButton( - style: ButtonStyle( + style: const ButtonStyle( // Specifying minimumSize to mimic the original minimumSize for // RaisedButton so that the semantics tree's rect and transform // match the original version of this test. - minimumSize: MaterialStateProperty.all(const Size(88, 36)), + minimumSize: MaterialStatePropertyAll(Size(88, 36)), ), onPressed: () { }, child: const Text('ABC'), @@ -728,11 +728,11 @@ void main() { }); testWidgets('ElevatedButton size is configurable by ThemeData.materialTapTargetSize', (WidgetTester tester) async { - final ButtonStyle style = ButtonStyle( + const ButtonStyle style = ButtonStyle( // Specifying minimumSize to mimic the original minimumSize for // RaisedButton so that the corresponding button size matches // the original version of this test. - minimumSize: MaterialStateProperty.all(const Size(88, 36)), + minimumSize: MaterialStatePropertyAll(Size(88, 36)), ); Widget buildFrame(MaterialTapTargetSize tapTargetSize, Key key) { @@ -797,7 +797,7 @@ void main() { // Specifying minimumSize to mimic the original minimumSize for // RaisedButton so that the corresponding button size matches // the original version of this test. - minimumSize: MaterialStateProperty.all(const Size(88, 36)), + minimumSize: const MaterialStatePropertyAll(Size(88, 36)), ), key: key, onPressed: () {}, @@ -861,8 +861,8 @@ void main() { child: Center( child: ElevatedButton.icon( key: buttonKey, - style: ButtonStyle( - padding: MaterialStateProperty.all(const EdgeInsets.fromLTRB(16, 5, 10, 12)), + style: const ButtonStyle( + padding: MaterialStatePropertyAll(EdgeInsets.fromLTRB(16, 5, 10, 12)), ), onPressed: () {}, icon: const Icon(Icons.add), diff --git a/packages/flutter/test/material/material_state_property_test.dart b/packages/flutter/test/material/material_state_property_test.dart index c95723080d..d6679e72e8 100644 --- a/packages/flutter/test/material/material_state_property_test.dart +++ b/packages/flutter/test/material/material_state_property_test.dart @@ -30,4 +30,16 @@ void main() { expect(value.resolve({MaterialState.disabled}), 123); expect(value.resolve({MaterialState.error}), 123); }); + + test('MaterialStatePropertyAll', () { + const MaterialStatePropertyAll value = MaterialStatePropertyAll(123); + expect(value.resolve({}), 123); + expect(value.resolve({MaterialState.hovered}), 123); + expect(value.resolve({MaterialState.focused}), 123); + expect(value.resolve({MaterialState.pressed}), 123); + expect(value.resolve({MaterialState.dragged}), 123); + expect(value.resolve({MaterialState.selected}), 123); + expect(value.resolve({MaterialState.disabled}), 123); + expect(value.resolve({MaterialState.error}), 123); + }); } diff --git a/packages/flutter/test/material/navigation_bar_theme_test.dart b/packages/flutter/test/material/navigation_bar_theme_test.dart index 6756577f51..bd79843943 100644 --- a/packages/flutter/test/material/navigation_bar_theme_test.dart +++ b/packages/flutter/test/material/navigation_bar_theme_test.dart @@ -26,14 +26,14 @@ void main() { testWidgets('Custom debugFillProperties', (WidgetTester tester) async { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); - NavigationBarThemeData( + const NavigationBarThemeData( height: 200.0, - backgroundColor: const Color(0x00000099), + backgroundColor: Color(0x00000099), elevation: 20.0, - indicatorColor: const Color(0x00000098), - indicatorShape: const CircleBorder(), - labelTextStyle: MaterialStateProperty.all(const TextStyle(fontSize: 7.0)), - iconTheme: MaterialStateProperty.all(const IconThemeData(color: Color(0x00000097))), + indicatorColor: Color(0x00000098), + indicatorShape: CircleBorder(), + labelTextStyle: MaterialStatePropertyAll(TextStyle(fontSize: 7.0)), + iconTheme: MaterialStatePropertyAll(IconThemeData(color: Color(0x00000097))), labelBehavior: NavigationDestinationLabelBehavior.alwaysHide, ).debugFillProperties(builder); @@ -47,10 +47,10 @@ void main() { expect(description[2], 'elevation: 20.0'); expect(description[3], 'indicatorColor: Color(0x00000098)'); expect(description[4], 'indicatorShape: CircleBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none))'); - expect(description[5], 'labelTextStyle: MaterialStateProperty.all(TextStyle(inherit: true, size: 7.0))'); + expect(description[5], 'labelTextStyle: MaterialStatePropertyAll(TextStyle(inherit: true, size: 7.0))'); // Ignore instance address for IconThemeData. - expect(description[6].contains('iconTheme: MaterialStateProperty.all(IconThemeData'), isTrue); + expect(description[6].contains('iconTheme: MaterialStatePropertyAll(IconThemeData'), isTrue); expect(description[6].contains('(color: Color(0x00000097))'), isTrue); expect(description[7], 'labelBehavior: NavigationDestinationLabelBehavior.alwaysHide'); diff --git a/packages/flutter/test/material/outlined_button_test.dart b/packages/flutter/test/material/outlined_button_test.dart index d899247065..72a93eecb6 100644 --- a/packages/flutter/test/material/outlined_button_test.dart +++ b/packages/flutter/test/material/outlined_button_test.dart @@ -922,11 +922,11 @@ void main() { textDirection: TextDirection.ltr, child: Center( child: OutlinedButton( - style: ButtonStyle( + style: const ButtonStyle( // Specifying minimumSize to mimic the original minimumSize for // RaisedButton so that the corresponding button size matches // the original version of this test. - minimumSize: MaterialStateProperty.all(const Size(88, 36)), + minimumSize: MaterialStatePropertyAll(Size(88, 36)), ), onPressed: () {}, child: const Text('ABC'), @@ -971,11 +971,11 @@ void main() { data: const MediaQueryData(), child: Center( child: OutlinedButton( - style: ButtonStyle( + style: const ButtonStyle( // Specifying minimumSize to mimic the original minimumSize for // RaisedButton so that the corresponding button size matches // the original version of this test. - minimumSize: MaterialStateProperty.all(const Size(88, 36)), + minimumSize: MaterialStatePropertyAll(Size(88, 36)), ), onPressed: () {}, child: const Text('ABC'), @@ -1000,11 +1000,11 @@ void main() { data: const MediaQueryData(textScaleFactor: 1.3), child: Center( child: OutlinedButton( - style: ButtonStyle( + style: const ButtonStyle( // Specifying minimumSize to mimic the original minimumSize for // RaisedButton so that the corresponding button size matches // the original version of this test. - minimumSize: MaterialStateProperty.all(const Size(88, 36)), + minimumSize: MaterialStatePropertyAll(Size(88, 36)), ), onPressed: () {}, child: const Text('ABC'), diff --git a/packages/flutter/test/material/radio_test.dart b/packages/flutter/test/material/radio_test.dart index 6f90f622ab..3959b93812 100644 --- a/packages/flutter/test/material/radio_test.dart +++ b/packages/flutter/test/material/radio_test.dart @@ -997,7 +997,7 @@ void main() { value: active, groupValue: true, onChanged: (_) { }, - fillColor: MaterialStateProperty.all(fillColor), + fillColor: const MaterialStatePropertyAll(fillColor), overlayColor: useOverlay ? MaterialStateProperty.resolveWith(getOverlayColor) : null, hoverColor: hoverColor, focusColor: focusColor, diff --git a/packages/flutter/test/material/radio_theme_test.dart b/packages/flutter/test/material/radio_theme_test.dart index 2eac106c65..f3a5f76e50 100644 --- a/packages/flutter/test/material/radio_theme_test.dart +++ b/packages/flutter/test/material/radio_theme_test.dart @@ -47,10 +47,10 @@ void main() { testWidgets('RadioThemeData implements debugFillProperties', (WidgetTester tester) async { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); - RadioThemeData( - mouseCursor: MaterialStateProperty.all(SystemMouseCursors.click), - fillColor: MaterialStateProperty.all(const Color(0xfffffff0)), - overlayColor: MaterialStateProperty.all(const Color(0xfffffff1)), + const RadioThemeData( + mouseCursor: MaterialStatePropertyAll(SystemMouseCursors.click), + fillColor: MaterialStatePropertyAll(Color(0xfffffff0)), + overlayColor: MaterialStatePropertyAll(Color(0xfffffff1)), splashRadius: 1.0, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, visualDensity: VisualDensity.standard, @@ -61,9 +61,9 @@ void main() { .map((DiagnosticsNode node) => node.toString()) .toList(); - expect(description[0], 'mouseCursor: MaterialStateProperty.all(SystemMouseCursor(click))'); - expect(description[1], 'fillColor: MaterialStateProperty.all(Color(0xfffffff0))'); - expect(description[2], 'overlayColor: MaterialStateProperty.all(Color(0xfffffff1))'); + expect(description[0], 'mouseCursor: MaterialStatePropertyAll(SystemMouseCursor(click))'); + expect(description[1], 'fillColor: MaterialStatePropertyAll(Color(0xfffffff0))'); + expect(description[2], 'overlayColor: MaterialStatePropertyAll(Color(0xfffffff1))'); expect(description[3], 'splashRadius: 1.0'); expect(description[4], 'materialTapTargetSize: MaterialTapTargetSize.shrinkWrap'); expect(description[5], equalsIgnoringHashCodes('visualDensity: VisualDensity#00000(h: 0.0, v: 0.0)')); @@ -85,7 +85,7 @@ void main() { return MaterialApp( theme: ThemeData( radioTheme: RadioThemeData( - mouseCursor: MaterialStateProperty.all(mouseCursor), + mouseCursor: const MaterialStatePropertyAll(mouseCursor), fillColor: MaterialStateProperty.resolveWith((Set states) { if (states.contains(MaterialState.selected)) { return selectedFillColor; @@ -167,7 +167,7 @@ void main() { return MaterialApp( theme: ThemeData( radioTheme: RadioThemeData( - mouseCursor: MaterialStateProperty.all(themeMouseCursor), + mouseCursor: const MaterialStatePropertyAll(themeMouseCursor), fillColor: MaterialStateProperty.resolveWith((Set states) { if (states.contains(MaterialState.selected)) { return themeSelectedFillColor; @@ -346,14 +346,14 @@ void main() { Widget buildRadio({required bool active}) { return MaterialApp( theme: ThemeData( - radioTheme: RadioThemeData( - fillColor: MaterialStateProperty.all(globalThemeFillColor), + radioTheme: const RadioThemeData( + fillColor: MaterialStatePropertyAll(globalThemeFillColor), ), ), home: Scaffold( body: RadioTheme( - data: RadioThemeData( - fillColor: MaterialStateProperty.all(localThemeFillColor), + data: const RadioThemeData( + fillColor: MaterialStatePropertyAll(localThemeFillColor), ), child: Radio( value: active ? 1 : 0, diff --git a/packages/flutter/test/material/slider_theme_test.dart b/packages/flutter/test/material/slider_theme_test.dart index 0a51d8406e..d8a4d51fb3 100644 --- a/packages/flutter/test/material/slider_theme_test.dart +++ b/packages/flutter/test/material/slider_theme_test.dart @@ -1248,7 +1248,7 @@ void main() { testWidgets('The mouse cursor is themeable', (WidgetTester tester) async { await tester.pumpWidget(_buildApp( ThemeData().sliderTheme.copyWith( - mouseCursor: MaterialStateProperty.all(SystemMouseCursors.text), + mouseCursor: const MaterialStatePropertyAll(SystemMouseCursors.text), ) )); diff --git a/packages/flutter/test/material/switch_test.dart b/packages/flutter/test/material/switch_test.dart index 579e42f8b4..637572a04b 100644 --- a/packages/flutter/test/material/switch_test.dart +++ b/packages/flutter/test/material/switch_test.dart @@ -1589,7 +1589,7 @@ void main() { autofocus: focused, value: active, onChanged: (_) { }, - thumbColor: MaterialStateProperty.all(thumbColor), + thumbColor: const MaterialStatePropertyAll(thumbColor), overlayColor: useOverlay ? MaterialStateProperty.resolveWith(getOverlayColor) : null, hoverColor: hoverColor, focusColor: focusColor, diff --git a/packages/flutter/test/material/switch_theme_test.dart b/packages/flutter/test/material/switch_theme_test.dart index 9f98f42497..6da9d3afd5 100644 --- a/packages/flutter/test/material/switch_theme_test.dart +++ b/packages/flutter/test/material/switch_theme_test.dart @@ -47,12 +47,12 @@ void main() { testWidgets('SwitchThemeData implements debugFillProperties', (WidgetTester tester) async { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); - SwitchThemeData( - thumbColor: MaterialStateProperty.all(const Color(0xfffffff0)), - trackColor: MaterialStateProperty.all(const Color(0xfffffff1)), - mouseCursor: MaterialStateProperty.all(SystemMouseCursors.click), + const SwitchThemeData( + thumbColor: MaterialStatePropertyAll(Color(0xfffffff0)), + trackColor: MaterialStatePropertyAll(Color(0xfffffff1)), + mouseCursor: MaterialStatePropertyAll(SystemMouseCursors.click), materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, - overlayColor: MaterialStateProperty.all(const Color(0xfffffff2)), + overlayColor: MaterialStatePropertyAll(Color(0xfffffff2)), splashRadius: 1.0, ).debugFillProperties(builder); @@ -61,11 +61,11 @@ void main() { .map((DiagnosticsNode node) => node.toString()) .toList(); - expect(description[0], 'thumbColor: MaterialStateProperty.all(Color(0xfffffff0))'); - expect(description[1], 'trackColor: MaterialStateProperty.all(Color(0xfffffff1))'); + expect(description[0], 'thumbColor: MaterialStatePropertyAll(Color(0xfffffff0))'); + expect(description[1], 'trackColor: MaterialStatePropertyAll(Color(0xfffffff1))'); expect(description[2], 'materialTapTargetSize: MaterialTapTargetSize.shrinkWrap'); - expect(description[3], 'mouseCursor: MaterialStateProperty.all(SystemMouseCursor(click))'); - expect(description[4], 'overlayColor: MaterialStateProperty.all(Color(0xfffffff2))'); + expect(description[3], 'mouseCursor: MaterialStatePropertyAll(SystemMouseCursor(click))'); + expect(description[4], 'overlayColor: MaterialStatePropertyAll(Color(0xfffffff2))'); expect(description[5], 'splashRadius: 1.0'); }); @@ -98,7 +98,7 @@ void main() { } return defaultTrackColor; }), - mouseCursor: MaterialStateProperty.all(mouseCursor), + mouseCursor: const MaterialStatePropertyAll(mouseCursor), materialTapTargetSize: materialTapTargetSize, overlayColor: MaterialStateProperty.resolveWith((Set states) { if (states.contains(MaterialState.focused)) { @@ -203,7 +203,7 @@ void main() { } return themeDefaultTrackColor; }), - mouseCursor: MaterialStateProperty.all(themeMouseCursor), + mouseCursor: const MaterialStatePropertyAll(themeMouseCursor), materialTapTargetSize: themeMaterialTapTargetSize, overlayColor: MaterialStateProperty.resolveWith((Set states) { if (states.contains(MaterialState.focused)) { @@ -429,16 +429,16 @@ void main() { Widget buildSwitch({bool selected = false, bool autofocus = false}) { return MaterialApp( theme: ThemeData( - switchTheme: SwitchThemeData( - thumbColor: MaterialStateProperty.all(globalThemeThumbColor), - trackColor: MaterialStateProperty.all(globalThemeTrackColor), + switchTheme: const SwitchThemeData( + thumbColor: MaterialStatePropertyAll(globalThemeThumbColor), + trackColor: MaterialStatePropertyAll(globalThemeTrackColor), ), ), home: Scaffold( body: SwitchTheme( - data: SwitchThemeData( - thumbColor: MaterialStateProperty.all(localThemeThumbColor), - trackColor: MaterialStateProperty.all(localThemeTrackColor), + data: const SwitchThemeData( + thumbColor: MaterialStatePropertyAll(localThemeThumbColor), + trackColor: MaterialStatePropertyAll(localThemeTrackColor), ), child: Switch( value: selected, diff --git a/packages/flutter/test/material/text_button_test.dart b/packages/flutter/test/material/text_button_test.dart index 8da1d07bb9..78a799c9a7 100644 --- a/packages/flutter/test/material/text_button_test.dart +++ b/packages/flutter/test/material/text_button_test.dart @@ -492,11 +492,11 @@ void main() { textDirection: TextDirection.ltr, child: Center( child: TextButton( - style: ButtonStyle( + style: const ButtonStyle( // Specifying minimumSize to mimic the original minimumSize for // RaisedButton so that the semantics tree's rect and transform // match the original version of this test. - minimumSize: MaterialStateProperty.all(const Size(88, 36)), + minimumSize: MaterialStatePropertyAll(Size(88, 36)), ), onPressed: () { }, child: const Text('ABC'),