lerp static method

Linearly interpolate between two Flutter logo descriptions.

Interpolates both the color and the style in a continuous fashion.

If both values are null, this returns null. Otherwise, it returns a non-null value. If one of the values is null, then the result is obtained by scaling the other value's opacity and margin.

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).

Values for t are usually obtained from an Animation<double>, such as an AnimationController.

See also:

Implementation

static FlutterLogoDecoration? lerp(
    FlutterLogoDecoration? a, FlutterLogoDecoration? b, double t) {
  assert(a == null || a.debugAssertIsValid());
  assert(b == null || b.debugAssertIsValid());
  if (a == null && b == null) return null;
  if (a == null) {
    return FlutterLogoDecoration._(
      b!.lightColor,
      b.darkColor,
      b.textColor,
      b.style,
      b.margin! * t,
      b._position,
      b._opacity * t.clamp(0.0, 1.0),
    );
  }
  if (b == null) {
    return FlutterLogoDecoration._(
      a.lightColor,
      a.darkColor,
      a.textColor,
      a.style,
      a.margin! * t,
      a._position,
      a._opacity * (1.0 - t).clamp(0.0, 1.0),
    );
  }
  if (t == 0.0) return a;
  if (t == 1.0) return b;
  return FlutterLogoDecoration._(
    Color.lerp(a.lightColor, b.lightColor, t),
    Color.lerp(a.darkColor, b.darkColor, t),
    Color.lerp(a.textColor, b.textColor, t),
    t < 0.5 ? a.style : b.style,
    EdgeInsets.lerp(a.margin, b.margin, t),
    a._position + (b._position - a._position) * t,
    (a._opacity + (b._opacity - a._opacity) * t).clamp(0.0, 1.0),
  );
}