パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v7.5.0

theme_extensions_builder_annotation

theme_extensions_builder 用の注釈。このパッケージは theme_extensions_builder がなければ何もしません。

AndroidiOSLinuxmacOSWebWindows
30日間ダウンロード
19.3万
いいね数
4
Pub ポイント
160

パッケージをインストール

flutter pub add theme_extensions_builder_annotation

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Flutterアプリケーションにおけるテーマ拡張の作成と管理をスムーズにするために、theme_extensions_builder向けのアノテーションを提供するDartパッケージです。theme_extensions_builderの補完として、アノテーションを通じてコンパイル時コード生成をサポートしています。このパッケージ自体には実行可能なロジックが含まれていませんが、テーマ設定の簡素化とボイラープレートの削減により開発者の生産性を向上させます。theme_extensions_builderパッケージとのみ連携することを目的としています。

用途

  • テーマ拡張クラスの生成
  • テーマ設定の簡素化
  • 型安全なテーマ処理の有効化
  • テーマ設定におけるボイラープレートの削減
  • ダイナミックなテーマワークフローのサポート

主な機能

  • コンパイル時コード生成
  • theme_extensions_builder との統合
  • 型安全なテーマ定義
  • 最小の実行時オーバーヘッド
  • アノテーション駆動型開発

適している対象

  • theme_extensions_builder を使用する Flutter 開発者
  • 保守可能なテーマシステムを重視するチーム
  • スケーラブルなテーマソリューションを必要とするプロジェクト
  • ボイラープレートを減らしたい開発者
  • 複雑または動的なテーマ要件を持つアプリ

注意事項

  • 機能するには theme_extensions_builder が必要です
  • 単独の機能はなし
  • コード生成に build_runner を使用しています
  • サポートされているFlutterプロジェクト内でのみ利用可能
  • シンプルな静的テーマには適していません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

theme_extensions_builder

pub package License: MIT

📖 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.

🎯 Quick Links

📦 Installation

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

🚀 Quick Start

Using @ThemeExtensions

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,
  );
}
Using @ThemeGen

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);
}

📋 Choose Your Annotation

@ThemeExtensions (Recommended)

For classes extending Flutter's ThemeExtension - ideal for most use cases.

Perfect for:

  • Full Flutter theme integration
  • Automatic theme switching with lerp animations
  • Easy access via BuildContext (e.g., context.appTheme)

Generates:

  • Complete ThemeExtension implementation with copyWith and lerp
  • BuildContext extension for convenient access
  • Equality operators and hashCode
@ThemeGen

For standalone theme data classes without ThemeExtension inheritance.

Perfect for:

  • Custom theme systems outside standard Flutter themes
  • Maximum control over class structure
  • Nested theme data objects

Generates:

  • copyWith and merge methods
  • Static lerp method
  • Equality operators and hashCode

📖 Example

Check out the example project for a comprehensive Flutter app with:

  • 5 Theme Extensions: App, Button, Card, Typography, and Spacing themes
  • Theme Switching: Seamless light/dark mode transitions
  • Custom Components: Buttons, cards, and typography showcases
  • Best Practices: Real-world organization patterns

🛠️ Development

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.

📄 License

MIT License - see the LICENSE file for details.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

ランキング