theme_tailor_toolbox 3.1.3 copy "theme_tailor_toolbox: ^3.1.3" to clipboard
theme_tailor_toolbox: ^3.1.3 copied to clipboard

Theming utilities and additional annotations for ThemeTailor code generator

Set of theming utilities and classes that work with and enhance theme_tailor code generator.

Table of contents #

How to use #

Install #

Install following dependencies:

flutter pub add --dev build_runner
flutter pub add --dev theme_tailor
flutter pub add theme_tailor_annotation

Add imports and part directive #

name.dart
import 'package:theme_tailor_toolbox/theme_tailor_toolbox.dart';

part 'name.tailor.dart'

With Toolbox, it is not necessary to additionaly import theme_tailor_annotation or flutter:foundation, as these imports are exported by Toolbox library. Therefore debugFillProperties will be implemented automatically in all Tailor-generated classes.

Create Theme class #

Head on to the theme_tailor documentation to check out detailed instruction on how to create theme extension classes.

Encoders #

Theme Tailor Toolbox provides encoders for a few selected types frequently used in theming. Encoders can either be accessed by specyfic class or static field on EncoderToolbox. Encoders have 2 implementations per type:

  • lerping (field animates per theme change)
  • nonLerping (field does not animate but changes instantly in the middle of changing theme when t == 0.5)

Lerping encoders #

Naming convention is following:
Non-nullable foo -> FooEncoder || EncoderToolbox.fooLerp
Nullable type Bar? -> BarNullableEncoder || EncoderToolbox.barNullableLerp

Type Encoder EncoderToolbox
Color ColorEncoder EncoderToolbox.colorLerp
Color? ColorNullableEncoder EncoderToolbox.colorNullableLerp
MaterialAccentColor MaterialAccentColorEncoder EncoderToolbox.materialAccentColorLerp
MaterialAccentColor? MaterialAccentColorNullableEncoder EncoderToolbox.materialAccentColorNullableLerp
MaterialColor MaterialColorEncoder EncoderToolbox.materialColorLerp
MaterialColor? MaterialColorNullableEncoder EncoderToolbox.materialColorNullableLerp
TextStyle TextStyleEncoder EncoderToolbox.textStyleLerp
TextStyle? TextStyleNullableEncoder EncoderToolbox.textStyleNullableLerp
LinearGradient LinearGradientEncoder EncoderToolbox.linearGradientLerp
LinearGradient? LinearGradientNullableEncoder EncoderToolbox.linearGradientNullableLerp
SweepGradient SweepGradientEncoder EncoderToolbox.sweepGradientLerp
SweepGradient? SweepGradientNullableEncoder EncoderToolbox.sweepGradientNullableLerp
RadialGradient RadialGradientEncoder EncoderToolbox.radialGradientLerp
RadialGradient? RadialGradientNullableEncoder EncoderToolbox.radialGradientNullableLerp

Non-lerping encoders #

Naming convention is following (examples):
Non-nullable foo -> NoLerpEncoder<foo> || EncoderToolbox.fooNoLerp
Nullable type Bar? -> NoLerpEncoder<Bar?> || EncoderToolbox.barNullableLerp

In case of NoLerpEncoder it is possible to use it with any type T as NoLerpEncoder<T>

Type NoLerpEncoder EncoderToolbox
Color NoLerpEncoder<Color> .colorNoLerp
Color? NoLerpEncoder<Color?> .colorNullableNoLerp
MaterialAccentColor NoLerpEncoder<MaterialAccentColor> .materialAccentColorNoLerp
MaterialAccentColor? NoLerpEncoder<MaterialAccentColor?> .materialAccentColorNullableNoLerp
MaterialColor NoLerpEncoder<MaterialColor?> .materialColorNoLerp
MaterialColor? NoLerpEncoder<MaterialColor?> .materialColorNullableNoLerp
TextStyle NoLerpEncoder<TextStyle?> .textStyleNoLerp
TextStyle? NoLerpEncoder<TextStyle?> .textStyleNullableNoLerp
LinearGradient NoLerpEncoder<LinearGradient?> .linearGradientNoLerp
LinearGradient? NoLerpEncoder<LinearGradient?> .linearGradientNullableNoLerp
SweepGradient NoLerpEncoder<SweepGradient?> .sweepGradientNoLerp
SweepGradient? NoLerpEncoder<SweepGradient?> .sweepGradientNullableNoLerp
RadialGradient NoLerpEncoder<RadialGradient?> .radialGradientNoLerp
RadialGradient? NoLerpEncoder<RadialGradient?> .radialGradientNullableNoLerp

Encoder usage #

/// Example of a class that only allows interpolation of selected fields
/// Disabling interpolation provided by default for types like Color
/// (Only foo and fooNullable will animate during theme changes)
@tailorMixin
@NoLerpEncoder<Color>()
@NoLerpEncoder<Color?>()
class _OnlyLerpFoo extends ThemeExtension<_OnlyLerpFoo> with _$_OnlyLerpFooTailorMixin {
    _OnlyLerpFoo({
    required this.foo,
    required this.bar,
    this.fooNullable,
    this.barNullable,
  });

    @ColorEncoder()
    final Color foo;
    final Color bar;
    @ColorNullableEncoder()
    final Color? fooNullable;
    final Color? barNullable;
}

final orangePink = _OnlyLerpFoo(foo: Colors.orange, bar: Colors.pink, fooNullable: Colors.orange, barNullable: Colors.pink);
final blueRed = _OnlyLerpFoo(foo: Colors.blue, bar: Colors.red, fooNullable: Colors.blue, barNullable: Colors.red);

/// Example of a class that disallows interpolation of selected fields
/// (foo and fooNullable will not animate during theme changes)
@tailorMixin
class _DontLerpFoo extends ThemeExtension<_DontLerpFoo> with _$_DontLerpFooTailorMixin {
  _DontLerpFoo({
    required this.foo,
    required this.bar,
    this.fooNullable,
    this.barNullable,
  });

    @NoLerpEncoder<Color>()
    final Color foo;
    final Color bar;
    @NoLerpEncoder<Color?>()
    final Color? fooNullable;
    final Color? barNullable;
}

final orangePink = _DontLerpFoo(foo: Colors.orange, bar: Colors.pink, fooNullable: Colors.orange, barNullable: Colors.pink);
final blueRed = _DontLerpFoo(foo: Colors.blue, bar: Colors.red, fooNullable: Colors.blue, barNullable: Colors.red);

Alternatively with EncoderToolbox:

/// Example of a class that only allows interpolation of selected fields
/// Disabling interpolation provided by default for types like Color
/// (Only foo and fooNullable will animate during theme changes)
@tailorMixin
@EncoderToolbox.colorNoLerp
@EncoderToolbox.colorNullableNoLerp
class _OnlyLerpFoo extends ThemeExtension<_OnlyLerpFoo> with _$_OnlyLerpFooTailorMixin {
    _OnlyLerpFoo({
      required this.foo,
      required this.bar,
      this.fooNullable,
      this.barNullable,
    });

    @EncoderToolbox.colorLerp
    final Color foo;
    final Color bar;
    @EncoderToolbox.colorNullableLerp
    final Color? fooNullable;
    final Color? barNullable;
}

final orangePink = _OnlyLerpFoo(foo: Colors.orange, bar: Colors.pink, fooNullable: Colors.orange, barNullable: Colors.pink);
final blueRed = _OnlyLerpFoo(foo: Colors.blue, bar: Colors.red, fooNullable: Colors.blue, barNullable: Colors.red);

/// Example of a class that disallows interpolation of selected fields
/// (foo and fooNullable will not animate during theme changes)
@tailorMixin
class _DontLerpFoo extends ThemeExtension<_DontLerpFoo> with _$_DontLerpFooTailorMixin {
    _DontLerpFoo({
      required this.foo,
      required this.bar,
      this.fooNullable,
      this.barNullable,
    });

    @NoLerpEncoder<Color>()
    final Color foo;
    final Color bar;
    @NoLerpEncoder<Color?>()
    final Color? fooNullable;
    final Color? barNullable;
}

final orangePink = _DontLerpFoo(foo: Colors.orange, bar: Colors.pink, fooNullable: Colors.orange, barNullable: Colors.pink);
final blueRed = _DontLerpFoo(foo: Colors.blue, bar: Colors.red, fooNullable: Colors.blue, barNullable: Colors.red);
1
likes
160
points
27
downloads

Publisher

unverified uploader

Weekly Downloads

Theming utilities and additional annotations for ThemeTailor code generator

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter, json_annotation, theme_tailor_annotation

More

Packages that depend on theme_tailor_toolbox