【发布时间】:2020-12-15 19:51:12
【问题描述】:
【问题讨论】:
【问题讨论】:
使用 custompaint 类
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: CustomPaint(
painter: BackgroundPaint(),
child: Container(
child: Center(
child: Text("hello"),
),
),
),
backgroundColor: Colors.blue,
),
);
}
}
class BackgroundPaint extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final paint = Paint();
Path path = Path();
paint.color = Colors.white;
path.lineTo(0, size.height *0.3);
path.quadraticBezierTo(size.width*0.70, size.height*0.60, size.width*1.2, 0);
path.close();
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return oldDelegate != this;
}
}
【讨论】: