theme_extensions_builder_annotation 7.1.0 copy "theme_extensions_builder_annotation: ^7.1.0" to clipboard
theme_extensions_builder_annotation: ^7.1.0 copied to clipboard

Annotations for the theme_extensions_builder. This package does nothing without theme_extensions_builder.

theme_extensions_builder_annotation #

pub package License: MIT

Annotations for theme_extensions_builder - a code generator for Flutter's ThemeExtension classes.

πŸ“¦ Overview #

This package provides annotations that work with theme_extensions_builder to automatically generate boilerplate code for Flutter theme extensions. It contains no logic itself and must be used together with the theme_extensions_builder package.

πŸš€ Installation #

Add this package to your dependencies:

flutter pub add theme_extensions_builder_annotation

Or manually in pubspec.yaml:

dependencies:
  theme_extensions_builder_annotation: ^7.0.0

Note: You also need to add theme_extensions_builder as a dev dependency. See the theme_extensions_builder documentation for complete setup instructions.

πŸ“š Available Annotations #

@ThemeExtensions #

The main annotation for generating ThemeExtension classes with full functionality.

Usage:

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 _$MyThemeMixin {
  const MyTheme({
    required this.primaryColor,
    required this.spacing,
  });

  final Color primaryColor;
  final double spacing;
}

Parameters:

  • buildContextExtension (bool, default: true) - Generate a BuildContext extension for easy theme access
  • contextAccessorName (String?, default: null) - Custom name for the context accessor
  • constructor (String?, default: null) - Name of the constructor to use

Examples:

// Custom context accessor name
@ThemeExtensions(contextAccessorName: 'customTheme')
class MyTheme extends ThemeExtension<MyTheme> with _$MyThemeMixin {
  // Access via: context.customTheme
}

// Disable BuildContext extension
@ThemeExtensions(buildContextExtension: false)
class MyTheme extends ThemeExtension<MyTheme> with _$MyThemeMixin {
  // Manual access: Theme.of(context).extension<MyTheme>()!
}

// Custom constructor
@ThemeExtensions(constructor: '_internal')
class MyTheme extends ThemeExtension<MyTheme> with _$MyThemeMixin {
  const MyTheme._internal({required this.primaryColor});
  
  final Color primaryColor;
  
  factory MyTheme({required Color primaryColor}) = MyTheme._internal;
}

@ThemeGen #

Alternative annotation for theme data classes that don't extend ThemeExtension.

Usage:

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

part 'alert_theme.g.theme.dart';

@ThemeGen()
class AlertThemeData with _$AlertThemeData {
  const AlertThemeData({
    this.duration = const Duration(milliseconds: 300),
    this.padding,
    this.textStyle,
  });

  final Duration duration;
  final EdgeInsets? padding;
  final TextStyle? textStyle;

  static AlertThemeData lerp(AlertThemeData? a, AlertThemeData? b, double t) =>
      _$AlertThemeData.lerp(a, b, t);
}

Parameters:

  • constructor (String?, default: null) - Name of the constructor to use

Constants #

For convenience, you can use the constant annotation:

// Instead of @ThemeExtensions()
@themeExtensions
class MyTheme extends ThemeExtension<MyTheme> with _$MyThemeMixin {
  // ...
}

// Instead of @ThemeGen()
@themeGen
class MyThemeData with _$MyThemeData {
  // ...
}

πŸ“– Full Documentation #

For complete documentation, examples, and advanced usage, see:

πŸ“„ License #

This project is licensed under the MIT License - see the LICENSE file for details.

🀝 Contributing #

Contributions are welcome! Visit the GitHub repository to contribute.

4
likes
150
points
19.6k
downloads

Publisher

verified publisherpro100.dev

Weekly Downloads

Annotations for the theme_extensions_builder. This package does nothing without theme_extensions_builder.

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

meta

More

Packages that depend on theme_extensions_builder_annotation