theme_extensions_builder_annotation
Anmerkungen für das theme_extensions_builder. Dieses Paket tut ohne theme_extensions_builder nichts.
Themen-Erweiterungsbaukasten
Englischer Projektschnappschuss. Aktuelle Inhalte auf GitHub.
📖 Full documentation: packages/theme_extensions_builder/README.md
theme_extensions_builder is a powerful code generator for Flutter's ThemeExtension classes. It eliminates boilerplate code by automatically generating copyWith, lerp, ==, and hashCode methods, along with convenient BuildContext extensions for easy theme access.
Add the packages to your project:
flutter pub add theme_extensions_builder_annotation
flutter pub add --dev theme_extensions_builder
flutter pub add --dev build_runner
Or add to pubspec.yaml:
dependencies:
theme_extensions_builder_annotation: ^7.5.0
dev_dependencies:
build_runner: ^2.13.0
theme_extensions_builder: ^7.5.0
For classes extending ThemeExtension:
import 'package:flutter/material.dart';
import 'package:theme_extensions_builder_annotation/theme_extensions_builder_annotation.dart';
part 'app_theme.g.theme.dart';
@ThemeExtensions()
class AppTheme extends ThemeExtension<AppTheme> with _$AppTheme {
const AppTheme({
required this.primaryColor,
required this.spacing,
});
final Color primaryColor;
final double spacing;
}
Generate code:
dart run build_runner build
Use in your app:
Widget build(BuildContext context) {
final theme = context.appTheme;
return Container(
padding: EdgeInsets.all(theme.spacing),
color: theme.primaryColor,
);
}
For standalone theme data classes:
@ThemeGen()
class ButtonThemeData with _$ButtonThemeData {
const ButtonThemeData({
required this.backgroundColor,
this.borderRadius = 8.0,
});
final Color backgroundColor;
final double borderRadius;
static ButtonThemeData? lerp(ButtonThemeData? a, ButtonThemeData? b, double t) =>
_$ButtonThemeData.lerp(a, b, t);
}
For classes extending Flutter's ThemeExtension - ideal for most use cases.
Perfect for:
context.appTheme)Generates:
ThemeExtension implementation with copyWith and lerpFor standalone theme data classes without ThemeExtension inheritance.
Perfect for:
Generates:
copyWith and merge methodslerp methodCheck out the example project for a comprehensive Flutter app with:
The repository is a pub workspace: one flutter pub get at the root resolves every package, including the example app.
flutter pub get
scripts/prepare_push.sh # format, analyze, build and test every package
scripts/update_goldens.sh # regenerate the golden files after a generator change
The generator tests run on the Dart SDK alone. The Flutter classes the fixtures use are small stand-ins in packages/theme_extensions_builder/test/fixtures/flutter_stubs.dart, with the same lerp and merge signatures as the real ones. The example app is where the generated code meets the real framework, so CI regenerates and analyzes it on every push.
MIT License - see the LICENSE file for details.
Nach Anwendungsfall filtern, Aktivität vergleichen und vor der Nutzung das Originalprojekt prüfen.
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗