Line data Source code
1 : import 'dart:ui' show lerpDouble;
2 :
3 : import 'package:flutter/widgets.dart';
4 : import 'package:theme_tailor_annotation/theme_tailor_annotation.dart';
5 :
6 : /// Interpolates `double` token values so theme transitions ease the scale
7 : /// instead of snapping at the midpoint, which is the generator's default for
8 : /// `double`. Used by the radius and spacing bundles.
9 : ///
10 : /// ```dart
11 : /// @TailorMixin(encoders: [DoubleLerpEncoder()])
12 : /// class FossRadii extends ThemeExtension<FossRadii> { /* double fields */ }
13 : /// ```
14 : class DoubleLerpEncoder extends ThemeEncoder<double> {
15 : /// Creates the encoder.
16 2 : const DoubleLerpEncoder();
17 :
18 3 : @override
19 3 : double lerp(double a, double b, double t) => lerpDouble(a, b, t) ?? b;
20 : }
21 :
22 : /// Interpolates a `List<BoxShadow>` so elevation eases on theme transitions
23 : /// instead of snapping. Used by the shadow bundle.
24 : ///
25 : /// ```dart
26 : /// @TailorMixin(encoders: [BoxShadowListLerpEncoder()])
27 : /// class FossShadows extends ThemeExtension<FossShadows> { /* shadow lists */ }
28 : /// ```
29 : class BoxShadowListLerpEncoder extends ThemeEncoder<List<BoxShadow>> {
30 : /// Creates the encoder.
31 2 : const BoxShadowListLerpEncoder();
32 :
33 2 : @override
34 : List<BoxShadow> lerp(List<BoxShadow> a, List<BoxShadow> b, double t) =>
35 2 : BoxShadow.lerpList(a, b, t) ?? [];
36 : }
|