1

with this below implementation code we have this custom shape design:

enter image description here

and in this design i want to change that to:

enter image description here

as i just learn create custom shape i can't do that, is any body can help me how to achieve that?

thanks

import 'package:flutter/material.dart';

class WaveClipperTwo extends CustomClipper<Path> {
  bool reverse;

  WaveClipperTwo({this.reverse = false});

  @override
  Path getClip(Size size) {
    var path = Path();
    if(!reverse) {
      path.lineTo(0.0, size.height - 20);

      var firstControlPoint = Offset(size.width / 4, size.height);
      var firstEndPoint = Offset(size.width / 2.25, size.height - 30.0);
      path.quadraticBezierTo(firstControlPoint.dx, firstControlPoint.dy,
          firstEndPoint.dx, firstEndPoint.dy);

      var secondControlPoint =
          Offset(size.width - (size.width / 3.25), size.height - 65);
      var secondEndPoint = Offset(size.width, size.height - 40);
      path.quadraticBezierTo(secondControlPoint.dx, secondControlPoint.dy,
          secondEndPoint.dx, secondEndPoint.dy);

      path.lineTo(size.width, size.height - 40);
      path.lineTo(size.width, 0.0);
      path.close();
    }else{
      path.lineTo(0.0, 20);

      var firstControlPoint = Offset(size.width / 4, 0.0);
      var firstEndPoint = Offset(size.width / 2.25, 30.0);
      path.quadraticBezierTo(firstControlPoint.dx, firstControlPoint.dy,
          firstEndPoint.dx, firstEndPoint.dy);

      var secondControlPoint =
          Offset(size.width - (size.width / 3.25), 65);
      var secondEndPoint = Offset(size.width, 40);
      path.quadraticBezierTo(secondControlPoint.dx, secondControlPoint.dy,
          secondEndPoint.dx, secondEndPoint.dy);

      path.lineTo(size.width, size.height);
      path.lineTo(0.0, size.height);
      path.close();
    }

    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
DolDurma
  • 15,753
  • 51
  • 198
  • 377

1 Answers1

2

I think, you need something like this:

class WaveClipperTwo extends CustomClipper<Path> {
  bool reverse;

  WaveClipperTwo({this.reverse = false});

  final int _coefficient = 16;
  double get _minStep => 1 / _coefficient;
  double get _preCenter => _minStep * (_coefficient / 2 - 1);
  double get _postCenter => _minStep * (_coefficient / 2 + 1);
  double get _preEnd => _minStep * (_coefficient - 2);

  @override
  Path getClip(Size size) {
    var path = Path();
    path.moveTo(0.0, 0.0);
    if(!reverse) {
      path.lineTo(0.0, size.height - 20.0);
      path.lineTo(size.width * _preCenter, size.height - 20.0);
      path.cubicTo(size.width/2, size.height - 20.0, size.width/2, size.height - 40.0, size.width * _postCenter, size.height - 40.0);
      path.lineTo(size.width * _preEnd, size.height - 40.0);
      path.quadraticBezierTo(size.width, size.height - 40.0, size.width, size.height - 20.0);
      path.lineTo(size.width, 0.0);
      path.close();
    }else{
      path.lineTo(0.0, 20);
      path.lineTo(size.width * _preCenter, 20.0);
      path.cubicTo(size.width/2, 20.0, size.width/2, 40.0, size.width * _postCenter, 40.0);
      path.lineTo(size.width * _preEnd, 40.0);
      path.quadraticBezierTo(size.width, 40, size.width, 20.0);
      path.lineTo(size.width, 0.0);
      path.close();
    }

    return path;
  }

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

P.S. You can try to change _coefficient and choose what suits for you

Andrii Turkovskyi
  • 27,554
  • 16
  • 95
  • 105
  • I think that what i want to have :) please let me to check more, thanks – DolDurma Jul 11 '19 at 15:36
  • there is a little problem on curve [ScreenShot](http://s6.uplod.ir/i/00956/2961s81r8vmo.png) and how can i change blue height? – DolDurma Jul 12 '19 at 07:16
  • For now height = 20.0. I'd recommend to replace all `20.0` and `40.0` to some constants. And regarding curve at right - in `_preEnd` change 2 to 1 – Andrii Turkovskyi Jul 12 '19 at 07:26
  • @for `height` and your recommends i don't understand me, and for `_preEnd` is this as you said?`_preEnd => _minStep * (_coefficient - 1)` and how about change blue height? – DolDurma Jul 12 '19 at 07:44
  • 1
    For example change `20` to `40` and `40` to `60`. It'll be easier if they will be constants – Andrii Turkovskyi Jul 12 '19 at 08:13
  • could you help me on this question? https://stackoverflow.com/q/57488255/1830228 thanks – DolDurma Aug 17 '19 at 06:51