下面的代码可以创建一个客户path,它在topLefttopRight上没有曲线,你能帮我怎么做吗?

我需要制作与此屏幕截图相同的内容:

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;
  }
}

推荐答案

要在右上角和左上角添加圆角,我建议您使用arcToPoint:

以下是你可以使用它的方法:

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;
  }
}

Flutter相关问答推荐

类型flatter doctor get zsh:未找到命令:macO中flatter

Firebase Auth异常未被catch捕获

我可以在iOS设备上使用Ffltter实现Google Pay按钮吗?

Fighter:基于ChangeNotifier状态动态更新AppBar中的图标

Ffltter:发布版本中的Path NotFoundException

就像Flutter 中的头文件一样?

我想在Flutter中画一个箭头,但我似乎无法填满空间

如何使文本表格域在抖动中变圆?

如何将带有参数的函数传递给FIFTH中的自定义小部件

flatter_localizations错误在Null值上使用了Null判断运算符

如何在flutter中更改showModalBottomSheet小部件中CheckboxListTile小部件的值?

Flutter:如何在 Future 函数上添加网络判断和 showDialog

带按钮的 Riverpod future Provider

尽管海拔设置为 0,如何删除 appBar 下的下划线

在Flutter中为容器实现线性渐变背景动画

更改下拉按钮的背景 colored颜色 - flutter

切换 Firebase 项目后 Flutter FirebaseAuthException 'configuration-not-found'

如何在图像上点或(图像的一部分)在 flutter 中点击?

将一个 Flutter 应用程序集成到另一个 Flutter 应用程序中

单击列表视图导航到 Flutter 中的另一个页面