interpolate function Value interpolation
Returns an interpolator between the two arbitrary values a
and b
.
The interpolator implementation is based on the type of the end value b
,
using the following algorithm:
- If
b
is a number, use interpolateNumber. - If
b
is aColor
or a string that can be converted to aColor
, use interpolateRgb. - If
b
is a DateTime, use interpolateDate. - If
b
is a string, use interpolateString. - If
b
is a TypedData, use interpolateNumberList. - If
b
is a List, use interpolateList. - Otherwise, it uses the constant
b
.
It's important to note that, unless the chosen interpolator allows
otherwise, a
and b
must be of the same type.
Implementation
Object? Function(num) interpolate(Object? a, Object? b) {
return (b is num
? interpolateNumber
: b is String
? interpolateColorOrString
: b is Color
? interpolateRgb
: b is DateTime
? interpolateDate
: b is List
? interpolateList
: b is Map
? interpolateMap
: _object)(a, b);
}