Skip to content
pubscout

theme_extensions_builder_annotation

7.5.0, released 2 months ago by pro100.dev

Annotations for generating boilerplate code for Flutter ThemeExtension classes.

WASM-ready
$ flutter pub add theme_extensions_builder_annotation
Source repository

What it does

Provides annotations like @ThemeExtensions and @ThemeGen that work with the theme_extensions_builder package to automatically generate code for Flutter theme extensions. It handles things like lerping, copyWith, and context accessors.

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

Use it when

  • You are using theme_extensions_builder to create custom Flutter theme extensions.
  • You want to automatically generate boilerplate like copyWith and lerp for theme classes.

Skip it when

  • You are not using theme_extensions_builder.
  • You prefer writing your ThemeExtension boilerplate manually.

Strengths

  • Reduces boilerplate code for custom Flutter theme extensions.
  • Provides convenient annotations and field-level exclusions like @ignore.

Weaknesses

  • Does nothing without the theme_extensions_builder package.
  • Requires build_runner and code generation setup.

Setup

Kind
Pure Dart
Effort
Low
Code generation
Yes (build_runner)
Direct dependencies
1

Add theme_extensions_builder_annotation to dependencies, theme_extensions_builder and build_runner to dev dependencies, and run build_runner.

import 'package:flutter/material.dart';
import 'package:theme_extensions_builder_annotation/theme_extensions_builder_annotation.dart';

part 'my_theme.g.theme.dart';

@ThemeExtensions()
class MyTheme extends ThemeExtension<MyTheme> with _$MyTheme {
  const MyTheme({
    required this.primaryColor,
    required this.spacing,
  });

  final Color primaryColor;
  final double spacing;
}

Alternatives

Packages that do the same job and could replace theme_extensions_builder_annotation.

Works with

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