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.
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.
- theme_extensions_builder
Code generator for Flutter ThemeExtension classes to minimize boilerplate code.
77Compare - theme_tailor
Generates boilerplate for Flutter ThemeExtension classes using annotations.
89Compare - theme_extensions_builder_annotation
Annotations for generating boilerplate code for Flutter ThemeExtension classes.
78Compare - xdg_icons
XDG theme icons for Flutter.
62Compare
Works with
Packages commonly used together with theme_extensions_gen: ones it builds on, ones built on it, and its own family.
- analyzertheme_extensions_gen depends on itPerforms static analysis of Dart code for tool integration and embedding.
- yamltheme_extensions_gen depends on itA Dart library for parsing YAML documents into Dart data structures.
- globtheme_extensions_gen depends on itA file and directory globbing library that supports Bash-style path matching and listing.
- dart_styletheme_extensions_gen depends on itProvides an API and CLI to format Dart source code automatically.
- buildtheme_extensions_gen depends on itPackage for authoring build_runner compatible code generators.
- source_gentheme_extensions_gen depends on itSource code generation builders and utilities for the Dart build system.
- build_runnerUsed togetherA build system for Dart code generation and modular compilation.