defaultStyleOf method
Defines the button's default appearance.
The button child's Text and Icon widgets are rendered with the ButtonStyle's foreground color. The button's InkWell adds the style's overlay color when the button is focused, hovered or pressed. The button's background color becomes its Material color.
All of the ButtonStyle's defaults appear below. In this list
"Theme.foo" is shorthand for Theme.of(context).foo
. Color
scheme values like "onSurface(0.38)" are shorthand for
onSurface.withOpacity(0.38)
. MaterialStateProperty valued
properties that are not followed by by a sublist have the same
value for all states, otherwise the values are as specified for
each state, and "others" means all other states.
The textScaleFactor
is the value of
MediaQuery.of(context).textScaleFactor
and the names of the
EdgeInsets constructors and EdgeInsetsGeometry.lerp
have been
abbreviated for readability.
The color of the ButtonStyle.textStyle is not used, the ButtonStyle.foregroundColor color is used instead.
textStyle
- Theme.textTheme.buttonbackgroundColor
- disabled - Theme.colorScheme.onSurface(0.12)
- others - Theme.colorScheme.primary
foregroundColor
- disabled - Theme.colorScheme.onSurface(0.38)
- others - Theme.colorScheme.onPrimary
overlayColor
- hovered - Theme.colorScheme.onPrimary(0.08)
- focused or pressed - Theme.colorScheme.onPrimary(0.24)
shadowColor
- Theme.shadowColorelevation
- disabled - 0
- default - 2
- hovered or focused - 4
- pressed - 8
padding
- textScaleFactor <= 1 - horizontal(16)
1 < textScaleFactor <= 2
- lerp(horizontal(16), horizontal(8))2 < textScaleFactor <= 3
- lerp(horizontal(8), horizontal(4))3 < textScaleFactor
- horizontal(4)
minimumSize
- Size(64, 36)side
- nullshape
- RoundedRectangleBorder(borderRadius: BorderRadius.circular(4))mouseCursor
- disabled - SystemMouseCursors.forbidden
- others - SystemMouseCursors.click
visualDensity
- theme.visualDensitytapTargetSize
- theme.materialTapTargetSizeanimationDuration
- kThemeChangeDurationenableFeedback
- true
The default padding values for the GradientElevatedButton.icon factory are slightly different:
padding
textScaleFactor <= 1
- start(12) end(16)1 < textScaleFactor <= 2
- lerp(start(12) end(16), horizontal(8))2 < textScaleFactor <= 3
- lerp(horizontal(8), horizontal(4))3 < textScaleFactor
- horizontal(4)
The default value for side
, which defines the appearance of the button's
outline, is null. That means that the outline is defined by the button
shape's OutlinedBorder.side. Typically the default value of an
OutlinedBorder's side is BorderSide.none, so an outline is not drawn.
Implementation
@override
ButtonStyle defaultStyleOf(BuildContext context) {
final ThemeData theme = Theme.of(context);
final ColorScheme colorScheme = theme.colorScheme;
final EdgeInsetsGeometry scaledPadding = ButtonStyleButton.scaledPadding(
const EdgeInsets.symmetric(horizontal: 16),
const EdgeInsets.symmetric(horizontal: 8),
const EdgeInsets.symmetric(horizontal: 4),
MediaQuery.maybeOf(context)?.textScaleFactor ?? 1,
);
return styleFrom(
primary: colorScheme.primary,
onPrimary: colorScheme.onPrimary,
onSurface: colorScheme.onSurface,
shadowColor: theme.shadowColor,
elevation: 2,
textStyle: theme.textTheme.button,
padding: scaledPadding,
minimumSize: const Size(64, 36),
side: null,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(4))),
enabledMouseCursor: SystemMouseCursors.click,
disabledMouseCursor: SystemMouseCursors.forbidden,
visualDensity: theme.visualDensity,
tapTargetSize: theme.materialTapTargetSize,
animationDuration: kThemeChangeDuration,
enableFeedback: true,
);
}