【问题标题】:Flutter custom clipperFlutter 自定义裁剪器
【发布时间】:2020-12-15 19:51:12
【问题描述】:

我正在尝试使用自定义剪裁器。我正在尝试绘制这个弯曲的蓝色容器。不知何故,我似乎无法弄清楚(目前是菜鸟)。我可以帮助自定义裁剪器路径的代码 sn-p 吗?很可能我写错了路径。

图片如下:

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    使用 custompaint 类

    class _MyHomePageState extends State<MyHomePage>  {
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            body: CustomPaint(
              painter: BackgroundPaint(),
              child: Container(
                child: Center(
                  child: Text("hello"),
                ),
              ),
            ),
            backgroundColor: Colors.blue,
          ),
        );
      }
    }
    
    class BackgroundPaint extends CustomPainter {
      @override
      void paint(Canvas canvas, Size size) {
        final paint = Paint();
        Path path = Path();
        paint.color = Colors.white;
        path.lineTo(0, size.height *0.3);
        path.quadraticBezierTo(size.width*0.70, size.height*0.60, size.width*1.2, 0);
        path.close();
        canvas.drawPath(path, paint);
      }
    
      @override
      bool shouldRepaint(CustomPainter oldDelegate) {
        return oldDelegate != this;
      }
    }
    

    【讨论】:

    • 感谢您努力提供代码和输出。 ??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    • 2020-01-11
    • 1970-01-01
    • 2021-05-28
    相关资源
    最近更新 更多