如何用flutter画这个形状

问题描述 投票:0回答:1

我有一个聊天页面,在留言中我需要画一个自定义的形状so如何用flutter画这个形状,忽略紫色是截图来的。

Container(
  height: 0.1*MediaQuery.of(context).size.height,
  color: Color(0xffFFC20F),
  child: Text('some thing'),
)

row

flutter dart containers draw shapes
1个回答
0
投票

我想这个应该能帮到你。你可以根据自己的需要修改这些值。

class CustomClip extends CustomClipper<Path>{
  @override
  Path getClip(Size size){
    Path path = Path();
    path.moveTo(10,0);
    path.lineTo(10,size.height/2 - 10);
    path.lineTo(0,size.height/2);
    path.lineTo(10,size.height/2 + 10);
    path.lineTo(10,size.height);
    path.lineTo(size.width,size.height);
    path.lineTo(size.width,0);
    path.close();
    return path;
  }

  @override
  bool shouldReclip(CustomClipper clipper){
    return false;
  } 
}

然后你可以在你的代码中使用它作为

ClipPath(
  clipper:CustomClip(),
  child:Container(width:300,height:100,color:Colors.yellow),
);
© www.soinside.com 2019 - 2024. All rights reserved.