theme_tailor_toolbox 3.1.1

SDKflutter
Platformandroidioswindowslinuxmacosweb

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

TypeEncoderEncoderToolbox
ColorColorEncoderEncoderToolbox.colorLerp
Color?ColorNullableEncoderEncoderToolbox.colorNullableLerp
MaterialAccentColorMaterialAccentColorEncoderEncoderToolbox.materialAccentColorLerp
MaterialAccentColor?MaterialAccentColorNullableEncoderEncoderToolbox.materialAccentColorNullableLerp
MaterialColorMaterialColorEncoderEncoderToolbox.materialColorLerp
MaterialColor?MaterialColorNullableEncoderEncoderToolbox.materialColorNullableLerp
TextStyleTextStyleEncoderEncoderToolbox.textStyleLerp
TextStyle?TextStyleNullableEncoderEncoderToolbox.textStyleNullableLerp
LinearGradientLinearGradientEncoderEncoderToolbox.linearGradientLerp
LinearGradient?LinearGradientNullableEncoderEncoderToolbox.linearGradientNullableLerp
SweepGradientSweepGradientEncoderEncoderToolbox.sweepGradientLerp
SweepGradient?SweepGradientNullableEncoderEncoderToolbox.sweepGradientNullableLerp
RadialGradientRadialGradientEncoderEncoderToolbox.radialGradientLerp
RadialGradient?RadialGradientNullableEncoderEncoderToolbox.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>

TypeNoLerpEncoderEncoderToolbox
ColorNoLerpEncoder<Color>.colorNoLerp
Color?NoLerpEncoder<Color?>.colorNullableNoLerp
MaterialAccentColorNoLerpEncoder<MaterialAccentColor>.materialAccentColorNoLerp
MaterialAccentColor?NoLerpEncoder<MaterialAccentColor?>.materialAccentColorNullableNoLerp
MaterialColorNoLerpEncoder<MaterialColor?>.materialColorNoLerp
MaterialColor?NoLerpEncoder<MaterialColor?>.materialColorNullableNoLerp
TextStyleNoLerpEncoder<TextStyle?>.textStyleNoLerp
TextStyle?NoLerpEncoder<TextStyle?>.textStyleNullableNoLerp
LinearGradientNoLerpEncoder<LinearGradient?>.linearGradientNoLerp
LinearGradient?NoLerpEncoder<LinearGradient?>.linearGradientNullableNoLerp
SweepGradientNoLerpEncoder<SweepGradient?>.sweepGradientNoLerp
SweepGradient?NoLerpEncoder<SweepGradient?>.sweepGradientNullableNoLerp
RadialGradientNoLerpEncoder<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);