lerpOpacity static method

Widget lerpOpacity(
  1. Widget a,
  2. Widget b,
  3. double t, {
  4. AlignmentGeometry alignment = Alignment.center,
})

Linearly interpolates the opacity of a widget between two values.

This method is typically used in animations to create a smooth transition effect by blending the opacity of a widget over time.

Returns a Widget with the interpolated opacity.

Implementation

static Widget lerpOpacity(
  Widget a,
  Widget b,
  double t, {
  AlignmentGeometry alignment = Alignment.center,
}) {
  if (t == 0) {
    return a;
  } else if (t == 1) {
    return b;
  }
  double startOpacity = 1 - (t.clamp(0, 0.5) * 2);
  double endOpacity = t.clamp(0.5, 1) * 2 - 1;
  return Stack(
    fit: StackFit.passthrough,
    children: [
      Positioned.fill(
        child: Opacity(
          opacity: startOpacity,
          child: Align(alignment: alignment, child: a),
        ),
      ),
      Opacity(opacity: endOpacity, child: b),
    ],
  );
}