【发布时间】:2020-01-16 10:42:06
【问题描述】:
如何创建上述自定义的 clipPath 小部件? (我附上截图)
我试过了,但不是准确的输出
剪裁类
class MessageClipper extends CustomClipper<Path> {
final double borderRadius = 15;
@override
Path getClip(Size size) {
double width = size.width;
double height = size.height;
double rheight = height - height / 3;
double oneThird = width / 3;
final path = Path()
..lineTo(0, rheight - borderRadius)
..cubicTo(0, rheight - borderRadius, 0, rheight, borderRadius, rheight)
..lineTo(oneThird, rheight)
..lineTo(width/2-borderRadius, height-borderRadius)
..cubicTo(width / 2 - borderRadius, height - borderRadius, width / 2,
height, width / 2 + borderRadius, height - borderRadius )
..lineTo(2 * oneThird, rheight)
..lineTo(width-borderRadius, rheight)
..cubicTo(width - borderRadius, rheight, width, rheight, width,
rheight - borderRadius)
..lineTo(width, 0)
..lineTo(0, 0);
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => true;
}
我在这里调用了这个方法
Center(
child: ClipPath(
clipper: MessageClipper(),
child: Container(
height: 41.66,
width: 91.63,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16.0)),
color: Colors.red,
),
child:
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
width: 7,
height: 8,
decoration: BoxDecoration(
color: Color(0xFFCCCCCC),
shape: BoxShape.circle),
),
Container(
width: 7,
height: 8,
decoration: BoxDecoration(
color: Color(0xFFCCCCCC),
shape: BoxShape.circle),
),
Container(
width: 7,
height: 8,
decoration: BoxDecoration(
color: Color(0xFFCCCCCC),
shape: BoxShape.circle),
),
Container(
width: 25,
height: 24,
decoration: BoxDecoration(
color: Color(0xFF1287BA),
shape: BoxShape.circle),
child: Center(
child: Text(
"17",
style: TextStyle(color: Color(0xFFFFFFFF)),
),
),
),
],
),
),)
)
无法像这样CenterContainer 内的项目,
【问题讨论】:
-
在您的 pubspec.yaml 文件中添加
flutter_custom_clippers作为依赖项或 Refer this link -
创建一个自定义的
ShapeBorder类 - 这样更容易获得好的结果