liquidSwipePath property

Path get liquidSwipePath

Generate the liquid swipe path

Implementation

Path get liquidSwipePath {
  const curve = Curves.easeOut;
  const sideOffsetCurve = Interval(0.5, 0.8, curve: Curves.easeInOut);

  final d = diameter + padding * 2;
  final r = d / 2;

  /// Canvas and touch position
  final w = size.width;
  final h = size.height;

  final xMax = this.xMax;
  final x = this.x;
  final y = localPosition.dy;

  final sideOffset = diameter * 0.4 +
      sideOffsetCurve.transform(progress) * (w - diameter * 0.4);

  final apexSpread = r * 1.2 + curve.transform(progress) * xMax * 0.5;
  final anchorOffset = r * 2.0 + curve.transform(progress) * xMax * 1.8;
  final anchorSpread = r * 2.0 + curve.transform(progress) * xMax * 1.2;

  final path = Path();

  /// Top side
  path
    ..moveTo(w, 0)
    ..lineTo(w - sideOffset, 0);

  /// Curvy lump
  path
    ..lineTo(w - sideOffset, y - anchorOffset)
    ..cubicTo(
      /// Control handle A
      w - sideOffset,
      y - anchorOffset + anchorSpread / 2,

      /// Control handle b
      x - r,
      y - apexSpread,

      /// Given point
      x - r,
      y,
    )
    ..cubicTo(
      /// Control handle A
      x - r,
      y + apexSpread,

      /// Control handle b
      w - sideOffset,
      y + anchorOffset - anchorSpread / 2,

      /// Given point
      w - sideOffset,
      y + anchorOffset,
    );

  /// Bottom side
  path
    ..lineTo(w - sideOffset, h)

    /// Canvas lower left
    ..lineTo(w, h)

    /// Close
    ..close();

  return path;
}