of static method

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

Typical usage is as follows:

ColorThemeData theme = ColorTheme.of(context);

Implementation

static ColorThemeData of(BuildContext context) {
  final parentTheme =
      context.dependOnInheritedWidgetOfExactType<ColorTheme>();
  if (parentTheme != null) return parentTheme.data;

  final globalTheme = Theme.of(context).extension<ColorThemeData>();
  final defaultTheme = ColorThemeData.defaults(context);
  return defaultTheme.merge(globalTheme);
}