lerp<T> method
Null safety
- ColorSwatch<
T> ? a, - ColorSwatch<
T> ? b, - double t
Linearly interpolate between two ColorSwatches.
It delegates to Color.lerp to interpolate the different colors of the swatch.
If either color is null, this function linearly interpolates from a transparent instance of the other color.
The t
argument represents position on the timeline, with 0.0 meaning
that the interpolation has not started, returning a
(or something
equivalent to a
), 1.0 meaning that the interpolation has finished,
returning b
(or something equivalent to b
), and values in between
meaning that the interpolation is at the relevant point on the timeline
between a
and b
. The interpolation can be extrapolated beyond 0.0 and
1.0, so negative values and values greater than 1.0 are valid (and can
easily be generated by curves such as Curves.elasticInOut). Each channel
will be clamped to the range 0 to 255.
Values for t
are usually obtained from an Animation<double>, such as
an AnimationController.
Implementation
static ColorSwatch<T>? lerp<T>(ColorSwatch<T>? a, ColorSwatch<T>? b, double t) {
final Map<T, Color> swatch;
if (b == null) {
if (a == null) {
return null;
} else {
swatch = a._swatch.map((T key, Color color) => MapEntry<T, Color>(key, Color.lerp(color, null, t)!));
}
} else {
if (a == null) {
swatch = b._swatch.map((T key, Color color) => MapEntry<T, Color>(key, Color.lerp(null, color, t)!));
} else {
swatch = a._swatch.map((T key, Color color) => MapEntry<T, Color>(key, Color.lerp(color, b[key], t)!));
}
}
return ColorSwatch<T>(Color.lerp(a, b, t)!.value, swatch);
}