lerp static method

Between a and b, slot by slot, as ButtonStyle.lerp: colours, sides, insets, sizes and type blend; shapes morph where their borders can (OutlinedBorder.lerp) and snap at the middle where they cannot; a value on one side only snaps at the middle.

Implementation

static DesignStyle? lerp(DesignStyle? a, DesignStyle? b, double t) {
  if (identical(a, b) || t == 0) return a;
  if (t == 1) return b;
  T? either<T>(T? x, T? y, T Function(T, T) f) =>
      x == null || y == null ? (t < .5 ? x : y) : f(x, y);
  WidgetStateProperty<T?>? l<T>(
    WidgetStateProperty<T?>? x,
    WidgetStateProperty<T?>? y,
    T Function(T, T) f,
  ) => WidgetStateProperty.lerp<T?>(x, y, t, (p, q, t) => either<T>(p, q, f));
  return DesignStyle(
    fill: l<Color>(a?.fill, b?.fill, (x, y) => Color.lerp(x, y, t)!),
    foreground: l<Color>(
      a?.foreground,
      b?.foreground,
      (x, y) => Color.lerp(x, y, t)!,
    ),
    edge: l<Color>(a?.edge, b?.edge, (x, y) => Color.lerp(x, y, t)!),
    overlay: l<Color>(a?.overlay, b?.overlay, (x, y) => Color.lerp(x, y, t)!),
    side: l<BorderSide>(a?.side, b?.side, (x, y) => BorderSide.lerp(x, y, t)),
    shape: l<OutlinedBorder>(
      a?.shape,
      b?.shape,
      (x, y) => OutlinedBorder.lerp(x, y, t)!,
    ),
    padding: l<EdgeInsetsGeometry>(
      a?.padding,
      b?.padding,
      (x, y) => EdgeInsetsGeometry.lerp(x, y, t)!,
    ),
    minimumSize: l<Size>(
      a?.minimumSize,
      b?.minimumSize,
      (x, y) => Size.lerp(x, y, t)!,
    ),
    textStyle: l<TextStyle>(
      a?.textStyle,
      b?.textStyle,
      (x, y) => TextStyle.lerp(x, y, t)!,
    ),
    iconSize: l<double>(
      a?.iconSize,
      b?.iconSize,
      (x, y) => lerpDouble(x, y, t)!,
    ),
  );
}