styleFrom static method
- Color? foregroundColor,
- Color? backgroundColor,
- Color? disabledForegroundColor,
- Color? disabledBackgroundColor,
- Color? shadowColor,
- Color? surfaceTintColor,
- double? elevation,
- TextStyle? textStyle,
- EdgeInsetsGeometry? padding,
- Size? minimumSize,
- Size? fixedSize,
- Size? maximumSize,
- BorderSide? side,
- OutlinedBorder? shape,
- MouseCursor? enabledMouseCursor,
- MouseCursor? disabledMouseCursor,
- VisualDensity? visualDensity,
- MaterialTapTargetSize? tapTargetSize,
- Duration? animationDuration,
- bool? enableFeedback,
- AlignmentGeometry? alignment,
- InteractiveInkFeatureFactory? splashFactory,
A static convenience method that constructs an outlined button ButtonStyle given simple values.
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.
disabled text and icon color.
Similarly, the enabledMouseCursor
and disabledMouseCursor
parameters are used to construct ButtonStyle.mouseCursor.
All of the other parameters are either used directly or used to create a MaterialStateProperty with a single value for all states.
All parameters default to null, by default this method returns a ButtonStyle that doesn't override anything.
For example, to override the default shape and outline for an MongolOutlinedButton, one could write:
MongolOutlinedButton(
style: OutlinedButton.styleFrom(
shape: StadiumBorder(),
side: BorderSide(width: 2, color: Colors.green),
),
)
Implementation
static ButtonStyle styleFrom({
Color? foregroundColor,
Color? backgroundColor,
Color? disabledForegroundColor,
Color? disabledBackgroundColor,
Color? shadowColor,
Color? surfaceTintColor,
double? elevation,
TextStyle? textStyle,
EdgeInsetsGeometry? padding,
Size? minimumSize,
Size? fixedSize,
Size? maximumSize,
BorderSide? side,
OutlinedBorder? shape,
MouseCursor? enabledMouseCursor,
MouseCursor? disabledMouseCursor,
VisualDensity? visualDensity,
MaterialTapTargetSize? tapTargetSize,
Duration? animationDuration,
bool? enableFeedback,
AlignmentGeometry? alignment,
InteractiveInkFeatureFactory? splashFactory,
}) {
final Color? foreground = foregroundColor;
final Color? disabledForeground = disabledForegroundColor;
final MaterialStateProperty<Color?>? foregroundColorProp =
(foreground == null && disabledForeground == null)
? null
: _OutlinedButtonDefaultColor(foreground, disabledForeground);
final MaterialStateProperty<Color?>? backgroundColorProp =
(backgroundColor == null && disabledBackgroundColor == null)
? null
: disabledBackgroundColor == null
? ButtonStyleButton.allOrNull<Color?>(backgroundColor)
: _OutlinedButtonDefaultColor(
backgroundColor, disabledBackgroundColor);
final MaterialStateProperty<Color?>? overlayColor =
(foreground == null) ? null : _OutlinedButtonDefaultOverlay(foreground);
final MaterialStateProperty<MouseCursor?> mouseCursor =
_OutlinedButtonDefaultMouseCursor(
enabledMouseCursor, disabledMouseCursor);
return ButtonStyle(
textStyle: ButtonStyleButton.allOrNull<TextStyle>(textStyle),
foregroundColor: foregroundColorProp,
backgroundColor: backgroundColorProp,
overlayColor: overlayColor,
shadowColor: ButtonStyleButton.allOrNull<Color>(shadowColor),
surfaceTintColor: ButtonStyleButton.allOrNull<Color>(surfaceTintColor),
elevation: ButtonStyleButton.allOrNull<double>(elevation),
padding: ButtonStyleButton.allOrNull<EdgeInsetsGeometry>(padding),
minimumSize: ButtonStyleButton.allOrNull<Size>(minimumSize),
maximumSize: ButtonStyleButton.allOrNull<Size>(maximumSize),
fixedSize: ButtonStyleButton.allOrNull<Size>(fixedSize),
side: ButtonStyleButton.allOrNull<BorderSide>(side),
shape: ButtonStyleButton.allOrNull<OutlinedBorder>(shape),
mouseCursor: mouseCursor,
visualDensity: visualDensity,
tapTargetSize: tapTargetSize,
animationDuration: animationDuration,
enableFeedback: enableFeedback,
alignment: alignment,
splashFactory: splashFactory,
);
}