@@ -34,6 +34,65 @@ class InterpolationTween extends Animatable {
34
34
extrapolateRight: extrapolateRight))(t);
35
35
}
36
36
37
+ class ColorInterpolationTween extends Animatable <Color > {
38
+ ColorInterpolationTween ({
39
+ @required this .inputRange,
40
+ @required this .outputRange,
41
+ this .curve = const _Linear ._(),
42
+ this .extrapolate,
43
+ this .extrapolateLeft = ExtrapolateType .extend,
44
+ this .extrapolateRight = ExtrapolateType .extend,
45
+ });
46
+
47
+ final List <double > inputRange;
48
+ final List <Color > outputRange;
49
+ final Curve curve;
50
+ final ExtrapolateType extrapolate;
51
+ final ExtrapolateType extrapolateLeft;
52
+ final ExtrapolateType extrapolateRight;
53
+ @override
54
+ Color transform (double t) {
55
+ // TODO: implement transform
56
+ return Color .fromARGB (
57
+ createInterpolation (InterpolationConfigType (
58
+ inputRange: inputRange,
59
+ outputRange: outputRange.map ((color) => color.alpha.toDouble ()).toList (),
60
+ curve: curve,
61
+ extrapolate: extrapolate,
62
+ extrapolateLeft: extrapolateLeft,
63
+ extrapolateRight: extrapolateRight))(t)
64
+ .toInt ()
65
+ .clamp (0 , 255 ),
66
+ createInterpolation (InterpolationConfigType (
67
+ inputRange: inputRange,
68
+ outputRange: outputRange.map ((color) => color.red.toDouble ()).toList (),
69
+ curve: curve,
70
+ extrapolate: extrapolate,
71
+ extrapolateLeft: extrapolateLeft,
72
+ extrapolateRight: extrapolateRight))(t)
73
+ .toInt ()
74
+ .clamp (0 , 255 ),
75
+ createInterpolation (InterpolationConfigType (
76
+ inputRange: inputRange,
77
+ outputRange: outputRange.map ((color) => color.green.toDouble ()).toList (),
78
+ curve: curve,
79
+ extrapolate: extrapolate,
80
+ extrapolateLeft: extrapolateLeft,
81
+ extrapolateRight: extrapolateRight))(t)
82
+ .toInt ()
83
+ .clamp (0 , 255 ),
84
+ createInterpolation (InterpolationConfigType (
85
+ inputRange: inputRange,
86
+ outputRange: outputRange.map ((color) => color.blue.toDouble ()).toList (),
87
+ curve: curve,
88
+ extrapolate: extrapolate,
89
+ extrapolateLeft: extrapolateLeft,
90
+ extrapolateRight: extrapolateRight))(t)
91
+ .toInt ()
92
+ .clamp (0 , 255 ),
93
+ );
94
+ }
95
+ }
37
96
38
97
enum ExtrapolateType {
39
98
extend,
0 commit comments