styleFrom static method
- Color? foregroundColor,
- Color? backgroundColor,
- Color? selectedForegroundColor,
- Color? selectedBackgroundColor,
- Color? disabledForegroundColor,
- Color? disabledBackgroundColor,
- Color? shadowColor,
- Color? surfaceTintColor,
- Color? iconColor,
- double? iconSize,
- Color? disabledIconColor,
- Color? overlayColor,
- 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 a segmented button ButtonStyle given simple values.
The foregroundColor, selectedForegroundColor, and disabledForegroundColor
colors are used to create a WidgetStateProperty ButtonStyle.foregroundColor,
and a derived ButtonStyle.overlayColor if overlayColor isn't specified.
If overlayColor is specified and its value is Colors.transparent
then the pressed/focused/hovered highlights are effectively defeated.
Otherwise a WidgetStateProperty with the same opacities as the
default is created.
The backgroundColor, selectedBackgroundColor and disabledBackgroundColor
colors are used to create a WidgetStateProperty ButtonStyle.backgroundColor.
Similarly, the enabledMouseCursor and disabledMouseCursor
parameters are used to construct ButtonStyle.mouseCursor.
The iconColor, disabledIconColor are used to construct
ButtonStyle.iconColor and iconSize is used to construct
ButtonStyle.iconSize.
All of the other parameters are either used directly or used to create a WidgetStateProperty with a single value for all states.
All parameters default to null. By default this method returns a ButtonStyle that doesn't override anything.
SegmentedButton<int>(
style: SegmentedButton.styleFrom(
foregroundColor: Colors.black,
selectedForegroundColor: Colors.white,
backgroundColor: Colors.amber,
selectedBackgroundColor: Colors.red,
),
segments: const <ButtonSegment<int>>[
ButtonSegment<int>(
value: 0,
label: Text('0'),
icon: Icon(Icons.calendar_view_day),
),
ButtonSegment<int>(
value: 1,
label: Text('1'),
icon: Icon(Icons.calendar_view_week),
),
],
selected: const <int>{0},
onSelectionChanged: (Set<int> selection) {},
),
Implementation
static ButtonStyle styleFrom({
Color? foregroundColor,
Color? backgroundColor,
Color? selectedForegroundColor,
Color? selectedBackgroundColor,
Color? disabledForegroundColor,
Color? disabledBackgroundColor,
Color? shadowColor,
Color? surfaceTintColor,
Color? iconColor,
double? iconSize,
Color? disabledIconColor,
Color? overlayColor,
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 MaterialStateProperty<Color?>? overlayColorProp =
(foregroundColor == null && selectedForegroundColor == null && overlayColor == null)
? null
: switch (overlayColor) {
(final Color overlayColor) when overlayColor.value == 0 =>
const MaterialStatePropertyAll<Color?>(Colors.transparent),
_ => _SegmentedButtonDefaultsM3.resolveStateColor(
foregroundColor,
selectedForegroundColor,
overlayColor,
),
};
return TextButton.styleFrom(
textStyle: textStyle,
shadowColor: shadowColor,
surfaceTintColor: surfaceTintColor,
iconColor: iconColor,
iconSize: iconSize,
disabledIconColor: disabledIconColor,
elevation: elevation,
padding: padding,
minimumSize: minimumSize,
fixedSize: fixedSize,
maximumSize: maximumSize,
side: side,
shape: shape,
enabledMouseCursor: enabledMouseCursor,
disabledMouseCursor: disabledMouseCursor,
visualDensity: visualDensity,
tapTargetSize: tapTargetSize,
animationDuration: animationDuration,
enableFeedback: enableFeedback,
alignment: alignment,
splashFactory: splashFactory,
).copyWith(
foregroundColor: _defaultColor(
foregroundColor,
disabledForegroundColor,
selectedForegroundColor,
),
backgroundColor: _defaultColor(
backgroundColor,
disabledBackgroundColor,
selectedBackgroundColor,
),
overlayColor: overlayColorProp,
);
}