defaultStyleOf method
- BuildContext context
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)
. WidgetStateProperty valued
properties that are not followed 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 "default font size" below refers to the font size specified in the
defaultStyleOf method (or 14.0 if unspecified), scaled by the
MediaQuery.textScalerOf(context).scale
method. 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.labelLargebackgroundColor
- disabled - Theme.colorScheme.onSurface(0.12)
- others - Theme.colorScheme.secondaryContainer
foregroundColor
- disabled - Theme.colorScheme.onSurface(0.38)
- others - Theme.colorScheme.onSecondaryContainer
overlayColor
- hovered - Theme.colorScheme.onSecondaryContainer(0.08)
- focused or pressed - Theme.colorScheme.onSecondaryContainer(0.12)
shadowColor
- Theme.colorScheme.shadowsurfaceTintColor
- nullelevation
- disabled - 0
- default - 0
- hovered - 1
- focused or pressed - 0
padding
default font size <= 14
- horizontal(16)14 < default font size <= 28
- lerp(horizontal(16), horizontal(8))28 < default font size <= 36
- lerp(horizontal(8), horizontal(4))36 < default font size
- horizontal(4)
minimumSize
- Size(64, 40)fixedSize
- nullmaximumSize
- Size.infiniteside
- nullshape
- StadiumBorder()mouseCursor
- disabled - SystemMouseCursors.basic
- others - SystemMouseCursors.click
visualDensity
- Theme.visualDensitytapTargetSize
- Theme.materialTapTargetSizeanimationDuration
- kThemeChangeDurationenableFeedback
- truealignment
- Alignment.centersplashFactory
- Theme.splashFactory
The default padding values for the FilledButton.icon factory are slightly different:
padding
default font size <= 14
- start(12) end(16)14 < default font size <= 28
- lerp(start(12) end(16), horizontal(8))28 < default font size <= 36
- lerp(horizontal(8), horizontal(4))36 < default font size
- 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.
Material 3 defaults
If ThemeData.useMaterial3 is set to true the following defaults will be used:
textStyle
- Theme.textTheme.labelLargebackgroundColor
- disabled - Theme.colorScheme.onSurface(0.12)
- others - Theme.colorScheme.secondaryContainer
foregroundColor
- disabled - Theme.colorScheme.onSurface(0.38)
- others - Theme.colorScheme.onSecondaryContainer
overlayColor
- hovered - Theme.colorScheme.onSecondaryContainer(0.08)
- focused or pressed - Theme.colorScheme.onSecondaryContainer(0.1)
shadowColor
- Theme.colorScheme.shadowsurfaceTintColor
- Colors.transparentelevation
- disabled - 0
- default - 1
- hovered - 3
- focused or pressed - 1
padding
default font size <= 14
- horizontal(24)14 < default font size <= 28
- lerp(horizontal(24), horizontal(12))28 < default font size <= 36
- lerp(horizontal(12), horizontal(6))36 < default font size
- horizontal(6)
minimumSize
- Size(64, 40)fixedSize
- nullmaximumSize
- Size.infiniteside
- nullshape
- StadiumBorder()mouseCursor
- disabled - SystemMouseCursors.basic
- others - SystemMouseCursors.click
visualDensity
- Theme.visualDensitytapTargetSize
- Theme.materialTapTargetSizeanimationDuration
- kThemeChangeDurationenableFeedback
- truealignment
- Alignment.centersplashFactory
- Theme.splashFactory
For the FilledButton.icon factory, the start (generally the left) value of ButtonStyle.padding is reduced from 24 to 16.
Implementation
@override
ButtonStyle defaultStyleOf(BuildContext context) {
return switch (_variant) {
_FilledButtonVariant.filled => _FilledButtonDefaultsM3(context),
_FilledButtonVariant.tonal => _FilledTonalButtonDefaultsM3(context),
};
}