of method Null safety

ButtonThemeData of(
  1. BuildContext context
)

The closest instance of this class that encloses the given context.

Typical usage is as follows:

ButtonThemeData theme = ButtonTheme.of(context);

Implementation

static ButtonThemeData of(BuildContext context) {
  final ButtonTheme? inheritedButtonTheme = context.dependOnInheritedWidgetOfExactType<ButtonTheme>();
  ButtonThemeData? buttonTheme = inheritedButtonTheme?.data;
  if (buttonTheme?.colorScheme == null) { // if buttonTheme or buttonTheme.colorScheme is null
    final ThemeData theme = Theme.of(context);
    buttonTheme ??= theme.buttonTheme;
    if (buttonTheme.colorScheme == null) {
      buttonTheme = buttonTheme.copyWith(
        colorScheme: theme.buttonTheme.colorScheme ?? theme.colorScheme,
      );
      assert(buttonTheme.colorScheme != null);
    }
  }
  return buttonTheme!;
}