diff --git a/packages/flutter/lib/src/material/button_style.dart b/packages/flutter/lib/src/material/button_style.dart index 51736adb22b..2067ed85cb8 100644 --- a/packages/flutter/lib/src/material/button_style.dart +++ b/packages/flutter/lib/src/material/button_style.dart @@ -75,7 +75,7 @@ import 'theme_data.dart'; /// /// ```dart /// TextButton( -/// style: TextButton.styleFrom(primary: Colors.green), +/// style: TextButton.styleFrom(foregroundColor: Colors.green), /// ) /// ``` /// @@ -85,7 +85,7 @@ import 'theme_data.dart'; /// MaterialApp( /// theme: ThemeData( /// textButtonTheme: TextButtonThemeData( -/// style: TextButton.styleFrom(primary: Colors.green), +/// style: TextButton.styleFrom(foregroundColor: Colors.green), /// ), /// ), /// home: MyAppHome(), diff --git a/packages/flutter/lib/src/material/desktop_text_selection.dart b/packages/flutter/lib/src/material/desktop_text_selection.dart index 0192f0e08f0..62690434de3 100644 --- a/packages/flutter/lib/src/material/desktop_text_selection.dart +++ b/packages/flutter/lib/src/material/desktop_text_selection.dart @@ -325,7 +325,7 @@ class _DesktopTextSelectionToolbarButton extends StatelessWidget { // TODO(hansmuller): Should be colorScheme.onSurface final ThemeData theme = Theme.of(context); final bool isDark = theme.colorScheme.brightness == Brightness.dark; - final Color primary = isDark ? Colors.white : Colors.black87; + final Color foregroundColor = isDark ? Colors.white : Colors.black87; return SizedBox( width: double.infinity, @@ -334,7 +334,7 @@ class _DesktopTextSelectionToolbarButton extends StatelessWidget { alignment: Alignment.centerLeft, enabledMouseCursor: SystemMouseCursors.basic, disabledMouseCursor: SystemMouseCursors.basic, - primary: primary, + foregroundColor: foregroundColor, shape: const RoundedRectangleBorder(), minimumSize: const Size(kMinInteractiveDimension, 36.0), padding: _kToolbarButtonPadding, diff --git a/packages/flutter/lib/src/material/elevated_button.dart b/packages/flutter/lib/src/material/elevated_button.dart index 1e610eaa501..750c6b7e8e9 100644 --- a/packages/flutter/lib/src/material/elevated_button.dart +++ b/packages/flutter/lib/src/material/elevated_button.dart @@ -100,14 +100,12 @@ class ElevatedButton extends ButtonStyleButton { /// A static convenience method that constructs an elevated button /// [ButtonStyle] given simple values. /// - /// The [onPrimary], and [onSurface] colors are used to create a - /// [MaterialStateProperty] [ButtonStyle.foregroundColor] value in the same - /// way that [defaultStyleOf] uses the [ColorScheme] colors with the same - /// names. Specify a value for [onPrimary] to specify the color of the - /// button's text and icons as well as the overlay colors used to indicate the - /// hover, focus, and pressed states. Use [primary] for the button's background - /// fill color and [onSurface] to specify the button's disabled text, icon, - /// and fill color. + /// The [foregroundColor] and [disabledForegroundColor] colors are used + /// to create a [MaterialStateProperty] [ButtonStyle.foregroundColor], and + /// a derived [ButtonStyle.overlayColor]. + /// + /// The [backgroundColor] and [disabledBackgroundColor] colors are + /// used to create a [MaterialStateProperty] [ButtonStyle.backgroundColor]. /// /// The button's elevations are defined relative to the [elevation] /// parameter. The disabled elevation is the same as the parameter @@ -131,9 +129,18 @@ class ElevatedButton extends ButtonStyleButton { /// /// ```dart /// ElevatedButton( - /// style: ElevatedButton.styleFrom(primary: Colors.green), + /// style: ElevatedButton.styleFrom(foregroundColor: Colors.green), /// ) /// ``` + /// + /// And to change the fill color: + /// + /// ```dart + /// ElevatedButton( + /// style: ElevatedButton.styleFrom(backgroundColor: Colors.green), + /// ) + /// ``` + /// static ButtonStyle styleFrom({ Color? foregroundColor, Color? backgroundColor, diff --git a/packages/flutter/lib/src/material/outlined_button.dart b/packages/flutter/lib/src/material/outlined_button.dart index b986e29a48e..4bf4e3fb7d5 100644 --- a/packages/flutter/lib/src/material/outlined_button.dart +++ b/packages/flutter/lib/src/material/outlined_button.dart @@ -103,13 +103,13 @@ class OutlinedButton extends ButtonStyleButton { /// A static convenience method that constructs an outlined button /// [ButtonStyle] given simple values. /// - /// The [primary], and [onSurface] colors are used to create a - /// [MaterialStateProperty] [ButtonStyle.foregroundColor] value in the same - /// way that [defaultStyleOf] uses the [ColorScheme] colors with the same - /// names. Specify a value for [primary] to specify the color of the button's - /// text and icons as well as the overlay colors used to indicate the hover, - /// focus, and pressed states. Use [onSurface] to specify the button's - /// disabled text and icon color. + /// + /// The [foregroundColor] and [disabledForegroundColor] colors are used + /// to create a [MaterialStateProperty] [ButtonStyle.foregroundColor], and + /// a derived [ButtonStyle.overlayColor]. + /// + /// The [backgroundColor] and [disabledBackgroundColor] colors are + /// used to create a [MaterialStateProperty] [ButtonStyle.backgroundColor]. /// /// Similarly, the [enabledMouseCursor] and [disabledMouseCursor] /// parameters are used to construct [ButtonStyle.mouseCursor]. diff --git a/packages/flutter/lib/src/material/snack_bar.dart b/packages/flutter/lib/src/material/snack_bar.dart index 9c9da4a4a47..5cc3c49d1a0 100644 --- a/packages/flutter/lib/src/material/snack_bar.dart +++ b/packages/flutter/lib/src/material/snack_bar.dart @@ -518,7 +518,7 @@ class _SnackBarState extends State { child: TextButtonTheme( data: TextButtonThemeData( style: TextButton.styleFrom( - primary: buttonColor, + foregroundColor: buttonColor, padding: EdgeInsets.symmetric(horizontal: horizontalPadding), ), ), diff --git a/packages/flutter/lib/src/material/stepper.dart b/packages/flutter/lib/src/material/stepper.dart index 4e261570023..a3fe58b535e 100644 --- a/packages/flutter/lib/src/material/stepper.dart +++ b/packages/flutter/lib/src/material/stepper.dart @@ -532,7 +532,7 @@ class _StepperState extends State with TickerProviderStateMixin { child: TextButton( onPressed: widget.onStepCancel, style: TextButton.styleFrom( - primary: cancelColor, + foregroundColor: cancelColor, padding: buttonPadding, shape: buttonShape, ), diff --git a/packages/flutter/lib/src/material/text_button.dart b/packages/flutter/lib/src/material/text_button.dart index d6f472320ae..cb82b5ff28d 100644 --- a/packages/flutter/lib/src/material/text_button.dart +++ b/packages/flutter/lib/src/material/text_button.dart @@ -112,13 +112,12 @@ class TextButton extends ButtonStyleButton { /// A static convenience method that constructs a text button /// [ButtonStyle] given simple values. /// - /// The [primary], and [onSurface] colors are used to create a - /// [MaterialStateProperty] [ButtonStyle.foregroundColor] value in the same - /// way that [defaultStyleOf] uses the [ColorScheme] colors with the same - /// names. Specify a value for [primary] to specify the color of the button's - /// text and icons as well as the overlay colors used to indicate the hover, - /// focus, and pressed states. Use [onSurface] to specify the button's - /// disabled text and icon color. + /// The [foregroundColor] and [disabledForegroundColor] colors are used + /// to create a [MaterialStateProperty] [ButtonStyle.foregroundColor], and + /// a derived [ButtonStyle.overlayColor]. + /// + /// The [backgroundColor] and [disabledBackgroundColor] colors are + /// used to create a [MaterialStateProperty] [ButtonStyle.backgroundColor]. /// /// Similarly, the [enabledMouseCursor] and [disabledMouseCursor] /// parameters are used to construct [ButtonStyle.mouseCursor]. @@ -137,7 +136,7 @@ class TextButton extends ButtonStyleButton { /// /// ```dart /// TextButton( - /// style: TextButton.styleFrom(primary: Colors.green), + /// style: TextButton.styleFrom(foregroundColor: Colors.green), /// ) /// ``` static ButtonStyle styleFrom({ diff --git a/packages/flutter/lib/src/material/text_selection_toolbar_text_button.dart b/packages/flutter/lib/src/material/text_selection_toolbar_text_button.dart index af50c53cbbd..d8b7d79dc54 100644 --- a/packages/flutter/lib/src/material/text_selection_toolbar_text_button.dart +++ b/packages/flutter/lib/src/material/text_selection_toolbar_text_button.dart @@ -109,11 +109,11 @@ class TextSelectionToolbarTextButton extends StatelessWidget { // TODO(hansmuller): Should be colorScheme.onSurface final ThemeData theme = Theme.of(context); final bool isDark = theme.colorScheme.brightness == Brightness.dark; - final Color primary = isDark ? Colors.white : Colors.black87; + final Color foregroundColor = isDark ? Colors.white : Colors.black87; return TextButton( style: TextButton.styleFrom( - primary: primary, + foregroundColor: foregroundColor, shape: const RoundedRectangleBorder(), minimumSize: const Size(kMinInteractiveDimension, kMinInteractiveDimension), padding: padding, diff --git a/packages/flutter/test/material/elevated_button_theme_test.dart b/packages/flutter/test/material/elevated_button_theme_test.dart index db694f4227f..71139333a22 100644 --- a/packages/flutter/test/material/elevated_button_theme_test.dart +++ b/packages/flutter/test/material/elevated_button_theme_test.dart @@ -44,10 +44,10 @@ void main() { }); group('[Theme, TextTheme, ElevatedButton style overrides]', () { - const Color primaryColor = Color(0xff000001); - const Color onSurfaceColor = Color(0xff000002); + const Color foregroundColor = Color(0xff000001); + const Color backgroundColor = Color(0xff000002); + const Color disabledColor = Color(0xff000003); const Color shadowColor = Color(0xff000004); - const Color onPrimaryColor = Color(0xff000005); const double elevation = 1; const TextStyle textStyle = TextStyle(fontSize: 12.0); const EdgeInsets padding = EdgeInsets.all(3); @@ -62,9 +62,10 @@ void main() { const AlignmentGeometry alignment = Alignment.centerLeft; final ButtonStyle style = ElevatedButton.styleFrom( - primary: primaryColor, - onPrimary: onPrimaryColor, - onSurface: onSurfaceColor, + foregroundColor: foregroundColor, + disabledForegroundColor: disabledColor, + backgroundColor: backgroundColor, + disabledBackgroundColor: disabledColor, shadowColor: shadowColor, elevation: elevation, textStyle: textStyle, @@ -126,16 +127,16 @@ void main() { void checkButton(WidgetTester tester) { final Material material = tester.widget(findMaterial); final InkWell inkWell = tester.widget(findInkWell); - expect(material.textStyle!.color, onPrimaryColor); + expect(material.textStyle!.color, foregroundColor); expect(material.textStyle!.fontSize, 12); - expect(material.color, primaryColor); + expect(material.color, backgroundColor); expect(material.shadowColor, shadowColor); expect(material.elevation, elevation); expect(MaterialStateProperty.resolveAs(inkWell.mouseCursor!, enabled), enabledMouseCursor); expect(MaterialStateProperty.resolveAs(inkWell.mouseCursor!, disabled), disabledMouseCursor); - expect(inkWell.overlayColor!.resolve(hovered), onPrimaryColor.withOpacity(0.08)); - expect(inkWell.overlayColor!.resolve(focused), onPrimaryColor.withOpacity(0.24)); - expect(inkWell.overlayColor!.resolve(pressed), onPrimaryColor.withOpacity(0.24)); + expect(inkWell.overlayColor!.resolve(hovered), foregroundColor.withOpacity(0.08)); + expect(inkWell.overlayColor!.resolve(focused), foregroundColor.withOpacity(0.24)); + expect(inkWell.overlayColor!.resolve(pressed), foregroundColor.withOpacity(0.24)); expect(inkWell.enableFeedback, enableFeedback); expect(material.borderRadius, null); expect(material.shape, shape); diff --git a/packages/flutter/test/material/outlined_button_test.dart b/packages/flutter/test/material/outlined_button_test.dart index 58063dc7d17..5b2e3f93410 100644 --- a/packages/flutter/test/material/outlined_button_test.dart +++ b/packages/flutter/test/material/outlined_button_test.dart @@ -1568,7 +1568,7 @@ void main() { expect(tester.getRect(find.byKey(labelKey)), const Rect.fromLTRB(104.0, 0.0, 154.0, 100.0)); }); - testWidgets('TextButton maximumSize', (WidgetTester tester) async { + testWidgets('OutlinedButton maximumSize', (WidgetTester tester) async { final Key key0 = UniqueKey(); final Key key1 = UniqueKey(); @@ -1582,7 +1582,7 @@ void main() { children: [ OutlinedButton( key: key0, - style: TextButton.styleFrom( + style: OutlinedButton.styleFrom( minimumSize: const Size(24, 36), maximumSize: const Size.fromWidth(64), ), @@ -1591,7 +1591,7 @@ void main() { ), OutlinedButton.icon( key: key1, - style: TextButton.styleFrom( + style: OutlinedButton.styleFrom( minimumSize: const Size(24, 36), maximumSize: const Size.fromWidth(104), ), diff --git a/packages/flutter/test/material/outlined_button_theme_test.dart b/packages/flutter/test/material/outlined_button_theme_test.dart index fd71f2827e6..642522728b2 100644 --- a/packages/flutter/test/material/outlined_button_theme_test.dart +++ b/packages/flutter/test/material/outlined_button_theme_test.dart @@ -49,9 +49,9 @@ void main() { }); group('[Theme, TextTheme, OutlinedButton style overrides]', () { - const Color primaryColor = Color(0xff000001); - const Color onSurfaceColor = Color(0xff000002); - const Color backgroundColor = Color(0xff000003); + const Color foregroundColor = Color(0xff000001); + const Color backgroundColor = Color(0xff000002); + const Color disabledColor = Color(0xff000003); const Color shadowColor = Color(0xff000004); const double elevation = 3; const TextStyle textStyle = TextStyle(fontSize: 12.0); @@ -67,9 +67,10 @@ void main() { const AlignmentGeometry alignment = Alignment.centerLeft; final ButtonStyle style = OutlinedButton.styleFrom( - primary: primaryColor, - onSurface: onSurfaceColor, + foregroundColor: foregroundColor, + disabledForegroundColor: disabledColor, backgroundColor: backgroundColor, + disabledBackgroundColor: disabledColor, shadowColor: shadowColor, elevation: elevation, textStyle: textStyle, @@ -130,15 +131,15 @@ void main() { void checkButton(WidgetTester tester) { final Material material = tester.widget(findMaterial); final InkWell inkWell = tester.widget(findInkWell); - expect(material.textStyle!.color, primaryColor); + expect(material.textStyle!.color, foregroundColor); expect(material.textStyle!.fontSize, 12); expect(material.color, backgroundColor); expect(material.shadowColor, shadowColor); expect(material.elevation, elevation); expect(MaterialStateProperty.resolveAs(inkWell.mouseCursor, enabled), enabledMouseCursor); expect(MaterialStateProperty.resolveAs(inkWell.mouseCursor, disabled), disabledMouseCursor); - expect(inkWell.overlayColor!.resolve(hovered), primaryColor.withOpacity(0.04)); - expect(inkWell.overlayColor!.resolve(focused), primaryColor.withOpacity(0.12)); + expect(inkWell.overlayColor!.resolve(hovered), foregroundColor.withOpacity(0.04)); + expect(inkWell.overlayColor!.resolve(focused), foregroundColor.withOpacity(0.12)); expect(inkWell.enableFeedback, enableFeedback); expect(material.borderRadius, null); expect(material.shape, shape); diff --git a/packages/flutter/test/material/snack_bar_test.dart b/packages/flutter/test/material/snack_bar_test.dart index 71b07752597..00b3945426a 100644 --- a/packages/flutter/test/material/snack_bar_test.dart +++ b/packages/flutter/test/material/snack_bar_test.dart @@ -499,9 +499,9 @@ void main() { dividerTheme: const DividerThemeData(color: Colors.black), bottomNavigationBarTheme: const BottomNavigationBarThemeData(type: BottomNavigationBarType.fixed), timePickerTheme: const TimePickerThemeData(backgroundColor: Colors.black), - textButtonTheme: TextButtonThemeData(style: TextButton.styleFrom(primary: Colors.red)), - elevatedButtonTheme: ElevatedButtonThemeData(style: ElevatedButton.styleFrom(primary: Colors.green)), - outlinedButtonTheme: OutlinedButtonThemeData(style: OutlinedButton.styleFrom(primary: Colors.blue)), + textButtonTheme: TextButtonThemeData(style: TextButton.styleFrom(foregroundColor: Colors.red)), + elevatedButtonTheme: ElevatedButtonThemeData(style: ElevatedButton.styleFrom(backgroundColor: Colors.green)), + outlinedButtonTheme: OutlinedButtonThemeData(style: OutlinedButton.styleFrom(foregroundColor: Colors.blue)), textSelectionTheme: const TextSelectionThemeData(cursorColor: Colors.black), dataTableTheme: const DataTableThemeData(), checkboxTheme: const CheckboxThemeData(), diff --git a/packages/flutter/test/material/text_button_theme_test.dart b/packages/flutter/test/material/text_button_theme_test.dart index 819397148b0..aaebf2e8d3d 100644 --- a/packages/flutter/test/material/text_button_theme_test.dart +++ b/packages/flutter/test/material/text_button_theme_test.dart @@ -44,9 +44,9 @@ void main() { }); group('[Theme, TextTheme, TextButton style overrides]', () { - const Color primaryColor = Color(0xff000001); - const Color onSurfaceColor = Color(0xff000002); - const Color backgroundColor = Color(0xff000003); + const Color foregroundColor = Color(0xff000001); + const Color backgroundColor = Color(0xff000002); + const Color disabledColor = Color(0xff000003); const Color shadowColor = Color(0xff000004); const double elevation = 3; const TextStyle textStyle = TextStyle(fontSize: 12.0); @@ -62,9 +62,10 @@ void main() { const AlignmentGeometry alignment = Alignment.centerLeft; final ButtonStyle style = TextButton.styleFrom( - primary: primaryColor, - onSurface: onSurfaceColor, + foregroundColor: foregroundColor, + disabledForegroundColor: disabledColor, backgroundColor: backgroundColor, + disabledBackgroundColor: disabledColor, shadowColor: shadowColor, elevation: elevation, textStyle: textStyle, @@ -125,15 +126,15 @@ void main() { void checkButton(WidgetTester tester) { final Material material = tester.widget(findMaterial); final InkWell inkWell = tester.widget(findInkWell); - expect(material.textStyle!.color, primaryColor); + expect(material.textStyle!.color, foregroundColor); expect(material.textStyle!.fontSize, 12); expect(material.color, backgroundColor); expect(material.shadowColor, shadowColor); expect(material.elevation, elevation); expect(MaterialStateProperty.resolveAs(inkWell.mouseCursor, enabled), enabledMouseCursor); expect(MaterialStateProperty.resolveAs(inkWell.mouseCursor, disabled), disabledMouseCursor); - expect(inkWell.overlayColor!.resolve(hovered), primaryColor.withOpacity(0.04)); - expect(inkWell.overlayColor!.resolve(focused), primaryColor.withOpacity(0.12)); + expect(inkWell.overlayColor!.resolve(hovered), foregroundColor.withOpacity(0.04)); + expect(inkWell.overlayColor!.resolve(focused), foregroundColor.withOpacity(0.12)); expect(inkWell.enableFeedback, enableFeedback); expect(material.borderRadius, null); expect(material.shape, shape); diff --git a/packages/flutter/test/material/theme_data_test.dart b/packages/flutter/test/material/theme_data_test.dart index facb1d8b486..9afd71bc99d 100644 --- a/packages/flutter/test/material/theme_data_test.dart +++ b/packages/flutter/test/material/theme_data_test.dart @@ -695,13 +695,13 @@ void main() { dialogTheme: const DialogTheme(backgroundColor: Colors.black), dividerTheme: const DividerThemeData(color: Colors.black), drawerTheme: const DrawerThemeData(), - elevatedButtonTheme: ElevatedButtonThemeData(style: ElevatedButton.styleFrom(primary: Colors.green)), + elevatedButtonTheme: ElevatedButtonThemeData(style: ElevatedButton.styleFrom(backgroundColor: Colors.green)), expansionTileTheme: const ExpansionTileThemeData(backgroundColor: Colors.black), floatingActionButtonTheme: const FloatingActionButtonThemeData(backgroundColor: Colors.black), listTileTheme: const ListTileThemeData(), navigationBarTheme: const NavigationBarThemeData(backgroundColor: Colors.black), navigationRailTheme: const NavigationRailThemeData(backgroundColor: Colors.black), - outlinedButtonTheme: OutlinedButtonThemeData(style: OutlinedButton.styleFrom(primary: Colors.blue)), + outlinedButtonTheme: OutlinedButtonThemeData(style: OutlinedButton.styleFrom(foregroundColor: Colors.blue)), popupMenuTheme: const PopupMenuThemeData(color: Colors.black), progressIndicatorTheme: const ProgressIndicatorThemeData(), radioTheme: const RadioThemeData(), @@ -709,7 +709,7 @@ void main() { snackBarTheme: const SnackBarThemeData(backgroundColor: Colors.black), switchTheme: const SwitchThemeData(), tabBarTheme: const TabBarTheme(labelColor: Colors.black), - textButtonTheme: TextButtonThemeData(style: TextButton.styleFrom(primary: Colors.red)), + textButtonTheme: TextButtonThemeData(style: TextButton.styleFrom(foregroundColor: Colors.red)), textSelectionTheme: const TextSelectionThemeData(cursorColor: Colors.black), timePickerTheme: const TimePickerThemeData(backgroundColor: Colors.black), toggleButtonsTheme: const ToggleButtonsThemeData(textStyle: TextStyle(color: Colors.black)),