of static method

Returns the nearest ButtonTheme.

Implementation

static ButtonThemeData of(BuildContext context) {
  final ButtonTheme? buttonTheme =
      context.dependOnInheritedWidgetOfExactType<ButtonTheme>();
  ButtonThemeData? buttonThemeData = buttonTheme?.data;

  if (buttonThemeData == null || !buttonThemeData._isConcrete) {
    final ThemeData themeData = Theme.of(context);
    final TextTheme textTheme = themeData.textTheme;
    final ColorScheme colorScheme = themeData.colorScheme;

    buttonThemeData ??= themeData.buttonTheme;

    final buttonValue =
        _ButtonThemeData(textTheme: textTheme, colorScheme: colorScheme);

    final Axis axis = buttonThemeData.axis ?? buttonValue.axis;
    final IconThemeData iconThemeData =
        buttonThemeData.iconThemeData ?? buttonValue.iconThemeData;
    final double itemSpacing =
        buttonThemeData.itemSpacing ?? buttonValue.itemSpacing;
    final double filledSpacing =
        buttonThemeData.filledSpacing ?? buttonValue.filledSpacing;
    final double height = buttonThemeData.height ?? buttonValue.height;
    final double minWidth = buttonThemeData.minWidth ?? buttonValue.minWidth;
    final TextStyle textStyle =
        buttonThemeData.textStyle ?? buttonValue.textStyle;
    final Color disabledColor =
        buttonThemeData.disabledColor ?? buttonValue.disabledColor;
    final Color color = buttonThemeData.color ?? buttonValue.color;
    final Color focusColor =
        buttonThemeData.focusColor ?? buttonValue.focusColor;
    final Color hoverColor =
        buttonThemeData.hoverColor ?? buttonValue.hoverColor;
    final Color highlightColor =
        buttonThemeData.highlightColor ?? buttonValue.highlightColor;
    final Color background =
        buttonThemeData.background ?? buttonValue.background;
    final Color focusBackground =
        buttonThemeData.focusBackground ?? buttonValue.focusBackground;
    final Color hoverBackground =
        buttonThemeData.hoverBackground ?? buttonValue.hoverBackground;
    final Color highlightBackground = buttonThemeData.highlightBackground ??
        buttonValue.highlightBackground;
    final Color foreground =
        buttonThemeData.foreground ?? buttonValue.foreground;
    final Color hoverForeground =
        buttonThemeData.hoverForeground ?? buttonValue.hoverForeground;
    final Color highlightForeground = buttonThemeData.highlightForeground ??
        buttonValue.highlightForeground;
    final Duration animationDuration =
        buttonThemeData.animationDuration ?? buttonValue.animationDuration;

    return buttonThemeData.copyWith(
      axis: axis,
      iconThemeData: iconThemeData,
      itemSpacing: itemSpacing,
      filledSpacing: filledSpacing,
      height: height,
      minWidth: minWidth,
      textStyle: textStyle,
      disabledColor: disabledColor,
      color: color,
      focusColor: focusColor,
      hoverColor: hoverColor,
      highlightColor: highlightColor,
      background: background,
      focusBackground: focusBackground,
      hoverBackground: hoverBackground,
      highlightBackground: highlightBackground,
      foreground: foreground,
      hoverForeground: hoverForeground,
      highlightForeground: highlightForeground,
      animationDuration: animationDuration,
    );
  }

  assert(buttonThemeData._isConcrete);

  return buttonThemeData;
}