defaultStyleOf method

  1. @override
ButtonStyle defaultStyleOf(
  1. BuildContext context
)
override

Defines the button's default appearance.

With the exception of ButtonStyle.side, which defines the outline, and ButtonStyle.padding, the returned style is the same as for TextButton.

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 and is transparent by default.

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 color of the ButtonStyle.textStyle is not used, the ButtonStyle.foregroundColor is used instead.

Material 2 defaults

  • textStyle - Theme.textTheme.button
  • backgroundColor - transparent
  • foregroundColor
    • disabled - Theme.colorScheme.onSurface(0.38)
    • others - Theme.colorScheme.primary
  • overlayColor
    • hovered - Theme.colorScheme.primary(0.08)
    • focused or pressed - Theme.colorScheme.primary(0.12)
  • shadowColor - Theme.shadowColor
  • elevation - 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, 36)
  • fixedSize - null
  • maximumSize - Size.infinite
  • side - BorderSide(width: 1, color: Theme.colorScheme.onSurface(0.12))
  • shape - RoundedRectangleBorder(borderRadius: BorderRadius.circular(4))
  • mouseCursor
    • disabled - SystemMouseCursors.basic
    • others - SystemMouseCursors.click
  • visualDensity - theme.visualDensity
  • tapTargetSize - theme.materialTapTargetSize
  • animationDuration - kThemeChangeDuration
  • enableFeedback - true
  • alignment - Alignment.center
  • splashFactory - InkRipple.splashFactory

Material 3 defaults

If ThemeData.useMaterial3 is set to true the following defaults will be used:

  • textStyle - Theme.textTheme.labelLarge
  • backgroundColor - transparent
  • foregroundColor
    • disabled - Theme.colorScheme.onSurface(0.38)
    • others - Theme.colorScheme.primary
  • overlayColor
    • hovered - Theme.colorScheme.primary(0.08)
    • focused or pressed - Theme.colorScheme.primary(0.1)
    • others - null
  • shadowColor - Colors.transparent,
  • surfaceTintColor - null
  • elevation - 0
  • 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 - null
  • maximumSize - Size.infinite
  • side
    • disabled - BorderSide(color: Theme.colorScheme.onSurface(0.12))
    • others - BorderSide(color: Theme.colorScheme.outline)
  • shape - StadiumBorder()
  • mouseCursor
    • disabled - SystemMouseCursors.basic
    • others - SystemMouseCursors.click
  • visualDensity - theme.visualDensity
  • tapTargetSize - theme.materialTapTargetSize
  • animationDuration - kThemeChangeDuration
  • enableFeedback - true
  • alignment - Alignment.center
  • splashFactory - Theme.splashFactory

For the OutlinedButton.icon factory, the start (generally the left) value of ButtonStyle.padding is reduced from 24 to 16.

Implementation

@override
ButtonStyle defaultStyleOf(BuildContext context) {
  final ThemeData theme = Theme.of(context);
  final ColorScheme colorScheme = theme.colorScheme;

  return Theme.of(context).useMaterial3
    ? _OutlinedButtonDefaultsM3(context)
    : styleFrom(
        foregroundColor: colorScheme.primary,
        disabledForegroundColor: colorScheme.onSurface.withOpacity(0.38),
        backgroundColor: Colors.transparent,
        disabledBackgroundColor: Colors.transparent,
        shadowColor: theme.shadowColor,
        elevation: 0,
        textStyle: theme.textTheme.labelLarge,
        padding: _scaledPadding(context),
        minimumSize: const Size(64, 36),
        maximumSize: Size.infinite,
        side: BorderSide(color: colorScheme.onSurface.withOpacity(0.12)),
        shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))),
        enabledMouseCursor: SystemMouseCursors.click,
        disabledMouseCursor: SystemMouseCursors.basic,
        visualDensity: theme.visualDensity,
        tapTargetSize: theme.materialTapTargetSize,
        animationDuration: kThemeChangeDuration,
        enableFeedback: true,
        alignment: Alignment.center,
        splashFactory: InkRipple.splashFactory,
      );
}