interpolate function Value interpolation

Object? Function(num) interpolate(
  1. Object? a,
  2. Object? b
)

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:

  1. If b is a number, use interpolateNumber.
  2. If b is a Color or a string that can be converted to a Color, use interpolateRgb.
  3. If b is a DateTime, use interpolateDate.
  4. If b is a string, use interpolateString.
  5. If b is a TypedData, use interpolateNumberList.
  6. If b is a List, use interpolateList.
  7. 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);
}