Skip to content

Instantly share code, notes, and snippets.

@AhmedAbouelkher
Last active February 1, 2023 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AhmedAbouelkher/9bd26c8eaa0092cf54edfc235979eddd to your computer and use it in GitHub Desktop.
Save AhmedAbouelkher/9bd26c8eaa0092cf54edfc235979eddd to your computer and use it in GitHub Desktop.
Wave clipper for Flutter (based on https://github.com/rafalbednarczuk/curved_navigation_bar)

A Wave clipper for nav bars or any other usecase.

class _WaveClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    const depth = 0.4; // depth of the wave
    const _s = .2; // slope of the wave
    const _loc = 0.8 / 2; // location of the wave
    final path = Path()
      ..moveTo(0, 0)
      ..lineTo((_loc - .05) * size.width, 0)
      ..cubicTo(
        (_loc + _s * 0.20) * size.width,
        size.height * 0.05,
        _loc * size.width,
        size.height * depth,
        (_loc + _s * 0.50) * size.width,
        size.height * depth,
      )
      ..cubicTo(
        (_loc + _s) * size.width,
        size.height * depth,
        (_loc + _s - _s * 0.10) * size.width,
        size.height * 0.05,
        (_loc + _s + 0.05) * size.width,
        0,
      )
      ..lineTo(size.width, 0)
      ..lineTo(size.width, size.height)
      ..lineTo(0, size.height)
      ..close();
    return path;
  }

  @override
  bool shouldReclip(covariant CustomClipper<Path> oldClipper) => false;
}

It's based on curved_navigation_bar Custom painter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment