flutter - 如何在 Flutter 中画一条带尖三角形的线?
解决方案
很简单,只需要了解如何使用快船。
方法如下:
你需要使用ClipPath
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.lightGreen,
appBar: AppBar(
title: Text("test"),
backgroundColor: Colors.deepOrange,
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
width: double.infinity,
height: 200,
color: Colors.red,
child: Center(
child: Text("Download"),
),
),
ClipPath(
clipper: TriangleClipper(),
child: Container(
color: Colors.red,
height: 10,
width: 20,
),
)
],
)),
);
}
并添加您的自定义剪裁器:
class TriangleClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
final path = Path();
path.lineTo(size.width, 0.0);
path.lineTo(size.width / 2, size.height);
path.close();
return path;
}
@override
bool shouldReclip(TriangleClipper oldClipper) => false;
}
就是这样,您将得到相同的结果。
推荐阅读
- android - 具有默认顶部和底部填充的 Android 应用
- java - Java JNA 无效的内存访问
- ios - 计算用户触摸
- r - 交互式 ggPredict whitin R Shiny FlexDashboard
- python - 自定义 celery 的速率限制和每个组的工人数量
- arrays - 如何用依赖于前一个值的值填充范围?
- android - Google Play 上传问题:“Your Android App Bundle need to have the package name com.xxbase”
- amazon-web-services - 我可以为 AWS 负载均衡器添加动态条件以自动添加新实例吗?
- python - 如何编写以下模式
- spring-boot - 如何通过 ip 地址访问 docker 服务