buttonTheme static method
ButtonThemeData
buttonTheme({
- required ColorScheme colorScheme,
- double? radius,
- EdgeInsetsGeometry padding = kButtonPadding,
- Size minButtonSize = kButtonMinSize,
An opinionated ButtonThemeData theme.
This theme is used to provide the same opinionated theme and style on
the deprecated buttons RaisedButton
, OutlineButtons
and FlatButton
.
Button theme has more limited theming capability and cannot match
the Material style buttons fully, this is an approximation.
The adjustable button corner radius
defaults to 20. This is the new
default in M3, Flutter SDK M2 defaults to 4.
The button padding
defaults to: EdgeInsets.symmetric(horizontal: 16).
It is used to make the buttons match the padding on the newer buttons.
Implementation
static ButtonThemeData buttonTheme({
/// Typically the same [ColorScheme] that is also used for your [ThemeData].
required final ColorScheme colorScheme,
/// The button corner radius.
///
/// Defaults to 20 [kButtonRadius].
final double? radius,
/// Padding for legacy button.
///
/// Defaults to EdgeInsets.symmetric(horizontal: 16).
/// This makes the legacy buttons same size as default margin on new ones.
final EdgeInsetsGeometry padding = kButtonPadding,
/// Minimum button size.
///
/// Defaults to `kButtonMinSize` = Size(40, 40).
final Size minButtonSize = kButtonMinSize,
}) =>
ButtonThemeData(
colorScheme: colorScheme,
minWidth: minButtonSize.width,
height: minButtonSize.height,
padding: padding,
layoutBehavior: ButtonBarLayoutBehavior.constrained,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
hoverColor: colorScheme.primary
.blendAlpha(Colors.white, kHoverAlphaBlend)
.withAlpha(kHoverAlpha),
focusColor: colorScheme.primary
.blendAlpha(Colors.white, kFocusAlphaBlend)
.withAlpha(kFocusAlpha),
highlightColor: colorScheme.primary
.blendAlpha(Colors.white, kHighlightAlphaBlend)
.withAlpha(kHighlightAlpha),
splashColor: colorScheme.primary
.blendAlpha(Colors.white, kSplashAlphaBlend)
.withAlpha(kSplashAlpha),
disabledColor: colorScheme.primary
.blendAlpha(colorScheme.onSurface, kDisabledAlphaBlend)
.withAlpha(kDisabledBackgroundAlpha),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(radius ?? kButtonRadius),
),
),
textTheme: ButtonTextTheme.primary,
);