出于某种原因,Stack
小部件不显示Container
带有CustomPaint
.
但是,如果从中删除Stack
,它可以正常工作。我在这里想念什么?
class _DemoNavBar extends State<DemoNavBar> {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
home:
Stack(
children: <Widget>[
Container(child: CustomPaint(painter: CurvePainter()))
],
)
);
}
}
class CurvePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint();
paint.color = Colors.green[800];
paint.style = PaintingStyle.fill;
var path = Path();
path.moveTo(0, size.height - 100);
path.lineTo(size.width * 0.5, size.height - 100);
path.quadraticBezierTo(size.width * 0.7, size.height, size.width * 0.9,
size.height - 100);
path.lineTo(size.width, size.height - 100);
path.lineTo(size.width, size.height);
path.lineTo(0, size.height);
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
谢谢!