我需要画这样的东西:
我尝试通过创建 aCustomClipper<Path>并在 a 中使用它来做到这一点ClipPath()
这是我的代码:
class ArcBackground extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ClipPath(
child: Container(
width: double.infinity,
height: 400.0,
color: Colors.orange,
),
clipper: RoundedClipper(),
);
}
}
class RoundedClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
var path = Path();
path.lineTo(0.0, size.height);
path.quadraticBezierTo(
size.width / 2,
size.height - 100,
size.width,
size.height
);
path.lineTo(size.width, 0.0);
path.close();
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
Run Code Online (Sandbox Code Playgroud)
这段代码给了我以下输出:
正如您所看到的,弧指向上是因为我将quadraticaBezierTo() y1属性设置为size.height - 100,我原以为可以通过将y1属性设为 来使弧指向下,size.height + 100但它不起作用。
我怎样才能实现向下指向的弧?
这对你有用吗?
@override
Path getClip(Size size) {
var path = Path();
path.lineTo(0.0, size.height-100);
path.quadraticBezierTo(
size.width / 2,
size.height,
size.width,
size.height - 100
);
path.lineTo(size.width, 0.0);
path.close();
return path;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1039 次 |
| 最近记录: |