extensions property

Iterable<ThemeExtension> get extensions

All ThemeExtensions defined in this theme.

Creating and passing a ThemeExtension to FThemeData

class BrandColor extends ThemeExtension<BrandColor> {
  final Color color;

  BrandColor(this.color);

  @override
  BrandColor copyWith({Color? color}) => BrandColor(color ?? this.color);

  @override
  BrandColor lerp(BrandColor? other, double t) {
    if (other is! BrandColor) return this;

   return BrandColor(Color.lerp(color, other.color, t)!);
  }
}

Passing it via constructor:

final theme = FThemeData(
  extensions: [BrandColor(Colors.blue)],
  ... // other fields omitted for brevity
);

Passing it via copyWith:

theme.copyWith(extensions: [BrandColor(Colors.blue)]);

Accessing the extension

final brandColor = context.theme.extension<BrandColor>();

It is recommended to define a getter for your ThemeExtension:

 BrandColor get brandColor => extension<BrandColor>();
 }

Implementation

Iterable<ThemeExtension<dynamic>> get extensions => _extensions.values;