mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Removed references to deprecated styleFrom parameters. (#108401)
This commit is contained in:
parent
7e683c023a
commit
4c104effe1
@ -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(),
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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].
|
||||
|
||||
@ -518,7 +518,7 @@ class _SnackBarState extends State<SnackBar> {
|
||||
child: TextButtonTheme(
|
||||
data: TextButtonThemeData(
|
||||
style: TextButton.styleFrom(
|
||||
primary: buttonColor,
|
||||
foregroundColor: buttonColor,
|
||||
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
|
||||
),
|
||||
),
|
||||
|
||||
@ -532,7 +532,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
|
||||
child: TextButton(
|
||||
onPressed: widget.onStepCancel,
|
||||
style: TextButton.styleFrom(
|
||||
primary: cancelColor,
|
||||
foregroundColor: cancelColor,
|
||||
padding: buttonPadding,
|
||||
shape: buttonShape,
|
||||
),
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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<Material>(findMaterial);
|
||||
final InkWell inkWell = tester.widget<InkWell>(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<MouseCursor>(inkWell.mouseCursor!, enabled), enabledMouseCursor);
|
||||
expect(MaterialStateProperty.resolveAs<MouseCursor>(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);
|
||||
|
||||
@ -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: <Widget>[
|
||||
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),
|
||||
),
|
||||
|
||||
@ -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<Material>(findMaterial);
|
||||
final InkWell inkWell = tester.widget<InkWell>(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<MouseCursor?>(inkWell.mouseCursor, enabled), enabledMouseCursor);
|
||||
expect(MaterialStateProperty.resolveAs<MouseCursor?>(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);
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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<Material>(findMaterial);
|
||||
final InkWell inkWell = tester.widget<InkWell>(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<MouseCursor?>(inkWell.mouseCursor, enabled), enabledMouseCursor);
|
||||
expect(MaterialStateProperty.resolveAs<MouseCursor?>(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);
|
||||
|
||||
@ -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)),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user