搜尋套件、儲存庫與 APP 分類

套件詳情v7.5.0

theme_extensions_builder_annotation

主題擴展建構器的註釋。此套件在沒有 theme_extensions_builder 的情況下什麼也不做。

AndroidiOSLinuxmacOSWebWindows
近 30 天下載
19.3萬
喜歡數
4
Pub 分數
160

安裝套件

flutter pub add theme_extensions_builder_annotation

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Dart 套件,為 theme_extensions_builder 提供註解,可簡化 Flutter 應用程式中主題擴展的建立與管理。它是 theme_extensions_builder 的輔助工具,透過註解提供編譯時期程式碼產生支援。此套件本身不包含可執行邏輯,但透過簡化主題設定並減少重複程式碼來提升開發者生產力。它僅設計用於與 theme_extensions_builder 套件搭配使用。

適用情境

  • 產生主題擴展類
  • 簡化主題設定
  • 啟用類型安全的主題處理
  • 減少主題設定中的樣板程式碼
  • 支援動態主題工作流程

主要特色

  • 編譯時期程式碼產生
  • 與 theme_extensions_builder 的整合
  • 類型安全的主題定義
  • 最小的執行時開銷
  • 基於註解的開發

適合對象

  • Flutter 開發者使用 theme_extensions_builder
  • 注重可維護主題系統的團隊
  • 需要可擴展主題解決方案的專案
  • 尋求減少樣板程式碼的開發人員
  • 具有複雜或動態主題需求的應用

使用建議

  • 需要 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 項

原始碼儲存庫

使用此套件的專案

所在榜單