textButtonTheme static method

TextButtonThemeData textButtonTheme({
  1. required ColorScheme colorScheme,
  2. double? radius,
  3. EdgeInsetsGeometry? padding,
  4. Size minButtonSize = kButtonMinSize,
})

An opinionated TextButtonThemeData theme.

Requires a ColorScheme, the color scheme would typically be equal the color scheme also used to define the color scheme for your app theme.

The adjustable button corner radius defaults to 20. This is the new default in M3, Flutter SDK M2 defaults to 4.

Implementation

static TextButtonThemeData textButtonTheme({
  /// Typically the same `ColorScheme` that is also used for your `ThemeData`.
  required final ColorScheme colorScheme,

  /// The button corner radius.
  ///
  /// Defaults to `kButtonRadius` = 20.
  final double? radius,

  /// Padding for the button theme.
  ///
  /// Defaults to null and uses `styleFrom` constructors default padding.
  ///
  /// M3 has more horizontal padding 24dp, but the tighter default padding
  /// in M2 that is 16dp looks fine as well when using stadium borders
  /// as in M3.
  /// Making the custom scalable padding and separate one for icon
  /// versions is rather involved, so sticking to defaults, but exposing the
  /// padding property for future or external use.
  final EdgeInsetsGeometry? padding,

  /// Minimum button size.
  ///
  /// Defaults to `kButtonMinSize` = Size(40, 40).
  final Size minButtonSize = kButtonMinSize,
}) =>
    TextButtonThemeData(
      style: TextButton.styleFrom(
        minimumSize: minButtonSize,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(
            Radius.circular(radius ?? kButtonRadius),
          ),
        ), // buttonShape,
        padding: padding,
      ).copyWith(
        foregroundColor: MaterialStateProperty.resolveWith<Color>(
          (Set<MaterialState> states) {
            if (states.contains(MaterialState.disabled)) {
              return colorScheme.primary
                  .blendAlpha(colorScheme.onSurface, kDisabledAlphaBlend)
                  .withAlpha(kDisabledForegroundAlpha);
            }
            return colorScheme.primary;
          },
        ),
        overlayColor: MaterialStateProperty.resolveWith<Color>(
          (Set<MaterialState> states) {
            if (states.contains(MaterialState.hovered)) {
              return colorScheme.primary.withAlpha(kHoverBackgroundAlpha);
            }
            if (states.contains(MaterialState.focused)) {
              return colorScheme.primary.withAlpha(kFocusBackgroundAlpha);
            }
            if (states.contains(MaterialState.pressed)) {
              return colorScheme.primary.withAlpha(kPressedBackgroundAlpha);
            }
            return Colors.transparent;
          },
        ),
      ),
    );