styleFrom static method
- Color? foregroundColor,
- Color? backgroundColor,
- Color? selectedForegroundColor,
- Color? selectedBackgroundColor,
- Color? disabledForegroundColor,
- Color? disabledBackgroundColor,
- Color? shadowColor,
- Color? surfaceTintColor,
- 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 MaterialStateProperty 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 MaterialStateProperty with the same opacities as the
default is created.
The backgroundColor
, selectedBackgroundColor
and disabledBackgroundColor
colors are used to create a MaterialStateProperty ButtonStyle.backgroundColor.
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.
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? 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?>? foregroundColorProp =
(foregroundColor == null && disabledForegroundColor == null && selectedForegroundColor == null)
? null
: _SegmentButtonDefaultColor(foregroundColor, disabledForegroundColor, selectedForegroundColor);
final MaterialStateProperty<Color?>? backgroundColorProp =
(backgroundColor == null && disabledBackgroundColor == null && selectedBackgroundColor == null)
? null
: _SegmentButtonDefaultColor(backgroundColor, disabledBackgroundColor, selectedBackgroundColor);
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,
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: foregroundColorProp,
backgroundColor: backgroundColorProp,
overlayColor: overlayColorProp,
);
}