flutterdart

Flutter adding 2 curve on top right and left CustomPainter edges


This below code can create a custome path and i it doesn't have curves on topLeft and topRight, could you please help me how can i do that?

i need to make the same as this screen shot:

enter image description here

original:

enter image description here

class CurvedPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    final paint = Paint()
      ..color = DV.$light
      ..style = PaintingStyle.fill;

    final path = Path()
      ..moveTo(0, size.height * 0.7)
      ..quadraticBezierTo(size.width * 0.25, size.height * 0.8, size.width * 0.4, size.height * 0.6)
      ..quadraticBezierTo(size.width * 0.65, size.height * 0.3, size.width, size.height * 0.6)
      ..lineTo(size.width, 0)
      ..lineTo(0, 0);

    canvas.drawPath(path, paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return false;
  }
}

Solution

  • To add rounded corners to top right and top left, I recommend you using arcToPoint:

    Here is how you could use it:

    class CurvedPainter extends CustomPainter {
      @override
      void paint(Canvas canvas, Size size) {
        final paint = Paint()
          ..color = DV.$light
          ..style = PaintingStyle.fill;
    
        final path = Path()
          ..moveTo(40, 0)
          ..arcToPoint(
            const Offset(0, 40),
            radius: const Radius.circular(40),
            clockwise: false,
          )
          ..lineTo(0, size.height * 0.7)
          ..quadraticBezierTo(size.width * 0.25, size.height * 0.8, size.width * 0.4, size.height * 0.6)
          ..quadraticBezierTo(size.width * 0.65, size.height * 0.3, size.width, size.height * 0.6)
          ..lineTo(size.width, 40)
          ..arcToPoint(
            Offset(size.width - 40, 0),
            radius: const Radius.circular(40),
            clockwise: false,
          )
          ..lineTo(40, 0)
          ..close();
    
        canvas.drawPath(path, paint);
      }
    
      @override
      bool shouldRepaint(CustomPainter oldDelegate) {
        return false;
      }
    }