Skip to content
pubscout

theme_extensions_gen

1.3.0, released 3 days ago by kalaganov.dev

Generate Flutter ThemeExtensions from annotated templates with context accessors and no boilerplate.

$ flutter pub add theme_extensions_gen
Source repository

What it does

Generates concrete ThemeExtension classes, copyWith, lerp, equality, debugFillProperties, and BuildContext extensions from abstract templates. Also aggregates theme implementations automatically via build_runner.

AI-written summary of version 1.2.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want to avoid boilerplate code when implementing Flutter ThemeExtensions.
  • You need automatic aggregation of theme extensions into ThemeData.
  • You want context accessors for your custom theme extensions.

Skip it when

  • Your project does not use code generation or build_runner.
  • You prefer writing ThemeExtension classes manually.

Strengths

  • Automates copyWith, lerp, equality, and hash code generation.
  • Generates BuildContext extensions for quick theme property access.
  • Aggregates all theme implementations into lists automatically.

Weaknesses

  • Requires running build_runner after making changes to theme templates.
  • Template constraints require specific constructor signatures.

Setup

Kind
Flutter widgets
Effort
Medium
Code generation
Yes (build_runner)
Direct dependencies
9

Add theme_extensions_gen_annotations, theme_extensions_gen, and build_runner to your pubspec, then run dart run build_runner watch.

@ThemeExtensionTemplate()
abstract interface class ThemedButtonTheme extends ThemeExtension<ThemedButtonTheme>
    with _$ThemedButtonThemeMixin, Diagnosticable {
  const factory ThemedButtonTheme({
    required Decoration decoration,
    required TextStyle textStyle,
    required EdgeInsets padding,
  }) = _$ThemedButtonTheme;
}

Alternatives

Packages that do the same job and could replace theme_extensions_gen.

Works with

Packages commonly used together with theme_extensions_gen: ones it builds on, ones built on it, and its own family.