如何在颤动中绘制一个一侧为半圆的矩形?

Posted

技术标签:

【中文标题】如何在颤动中绘制一个一侧为半圆的矩形?【英文标题】:How to draw a rectangle with one side as a half circle in flutter? 【发布时间】:2020-08-08 16:00:01 【问题描述】:

这就是我想要达到的目标(请原谅不完美,但你明白了):

我看到一些使用 Clipper 的教程,但它们似乎没有达到我想要的效果,我需要使用容器来绘制它,因为我想在上面放置一些文本。

class DrawCustomCircle extends CustomClipper<Path> 
  @override
  Path getClip(Size size) 
    final Path path = new Path();
    ...
    return path;
  
  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) 
    return true;
  

【问题讨论】:

【参考方案1】:

你可以使用BoxDecoration来制作这个形状:

Container(
          height: 100,
          width: 200,
          decoration: BoxDecoration(
            color: Colors.blue,
            shape: BoxShape.rectangle,
            borderRadius: BorderRadius.horizontal(
              left: Radius.circular(50.0),
            ),
          ),
        ),

结果:

【讨论】:

以上是关于如何在颤动中绘制一个一侧为半圆的矩形?的主要内容,如果未能解决你的问题,请参考以下文章