flutter 如何使用自定义画家绘制半圆

3npbholx  于 2022-11-17  发布在  Flutter
关注(0)|答案(1)|浏览(148)

我想画曲线像上面的图像谁能帮助我吗?

von4xj4u

von4xj4u1#

尝试quadraticBezierTo与油漆shader .发挥与quadraticBezierTo的值,以满足您的需要。

class MyCustomPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    Path path = Path()
      ..lineTo(20, 0)
      ..quadraticBezierTo(size.width / 2, size.height / 2, size.width, 0)
      ..lineTo(size.width, 20)
      ..quadraticBezierTo(size.width / 2, size.height / 1.3, 0, 20);

    Paint paint = Paint()
      ..shader =
          LinearGradient(colors: [Colors.blue, Colors.blue.withOpacity(.4)])
              .createShader(Rect.fromLTWH(0, 0, size.width, size.height));
    canvas.drawPath(path, paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}

相关问题