【发布时间】:2020-11-10 11:22:35
【问题描述】:
【问题讨论】:
-
我发现了一个与您类似的已回答问题。也许这会有所帮助stackoverflow.com/questions/56170150/…
标签: flutter flutter-layout flutter-design
【问题讨论】:
标签: flutter flutter-layout flutter-design
您可以使用ClipPath 类为您的容器提供自定义形状。
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: ClipPath(
child: Container(color: Colors.red),
clipper: MyCustomClipper(),
),
),
));
}
}
class MyCustomClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
Path path = Path()
..lineTo(size.width, 0)
..lineTo(size.width, size.height/2)
..lineTo(size.width/2, size.height)
..lineTo(0, size.height)
..close();
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
【讨论】:
ClipPath 不是为Container 提供自定义形状的最佳解决方案 - 为此使用ShapeDecoration,here 你有一些示例代码
lerp* 方法时,您可以像这里一样拥有“变形”形状:github.com/flutter/flutter/blob/c969b8af7b/packages/flutter/lib/…,这种“变形”可以应用于其他 @ 987654330@s 以及 - 检查 CornerDecorationTest 和 gist.github.com/pskink/… - 只需点击其中的 CornerDecorationTest 并观看魔术 ;-)