How to made CustomPaint like this in flutter

Viewed 703

I know it's not the best way but I really can't do this. How to made something like this. I'm suck in geometry. I try to do this with cubicTo but I cen't get this effect :/.

Can someone help me. Below is part of my code.

var sw = size.width;
var sh = size.height;

var path = Path();

path.cubicTo(sw/2, 0, sw/4, 0, 2*sw/4, 2*sh/4);
path.cubicTo(2*sw/3, 2*sh/3, sw/3, 0, sw, 0);
path.cubicTo(0, 0, 0, 0, sw, 0);
path.lineTo(sw, sh);
path.lineTo(0, sh);
path.close();

enter image description here

2 Answers

Check this out...

class Paintter extends CustomPainter{
  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = Paint()..color = Colors.orange;
    var path = Path();
    double factor = 100;
    path.lineTo(0, size.height);
    path.lineTo(size.width, size.height);
    path.lineTo(size.width, 0);
    path.lineTo(size.width - factor, 0);
    path.quadraticBezierTo(size.width/2, size.height, factor, 0);
    path.lineTo(0, 0);
    canvas.drawPath(path, paint);
  }

The output: enter image description here

Path@arcToPoint is useful for drawing circle/oval segments.

For example, for a circle with radius equal to half rect's height:

final w = size.width;
final h = size.height;
final r = h / 2;

final path = Path();
path.moveTo(0, 0);
path.lineTo(w / 2 - r, 0);
path.arcToPoint(
  Offset(w / 2 + r, 0),
  radius: Radius.circular(r),
  clockwise: false,
);
path.lineTo(w, 0);
path.lineTo(w, h);
path.lineTo(0, h);
path.close();

Result

Related