Skip to content
pubscout

theme_extensions_builder

7.5.1, released 4 weeks ago by pro100.dev

Code generator for Flutter ThemeExtension classes to minimize boilerplate code.

$ flutter pub add theme_extensions_builder
Source repository

What it does

Generates copyWith, lerp, merge, ==, hashCode methods, and BuildContext extensions for Flutter ThemeExtension and custom theme classes via annotations.

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

Use it when

  • You are implementing Flutter 3 ThemeExtension classes and want to eliminate boilerplate.
  • You want automatic BuildContext extensions for convenient access to your custom themes.

Skip it when

  • You prefer writing all theme extension methods and boilerplate manually.
  • You cannot use build_runner or code generation in your workflow.

Strengths

  • Eliminates repetitive boilerplate for copyWith, lerp, merge, equality, and hash code.
  • Provides convenient BuildContext extensions for theme access.
  • Supports complex types like EdgeInsets, TextStyles, Durations, and custom types.

Weaknesses

  • Requires running build_runner for code generation.
  • copyWith cannot set a nullable field to null.

Setup

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

Requires adding build_runner and theme_extensions_builder as dev dependencies and running build_runner to generate files.

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});
  final Color primaryColor;
}

Alternatives

Packages that do the same job and could replace theme_extensions_builder.

Works with

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