class BottomCurvePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
// TODO: implement paint
Paint paint = Paint();
paint.color = Colors.black;
paint.style = PaintingStyle.stroke;
paint.strokeWidth = 5.0;
Path path = Path();
path.lineTo(size.width, size.height);
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
// TODO: implement shouldRepaint
//throw UnimplementedError();
return true;
}
}
我在家里打电话的方式如下:-
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.orange,
child: CustomPaint(
painter: BottomCurvePainter(),
),
),
);
}
}
但是这似乎不起作用。但是,如果我删除了脚手架小部件并直接返回容器,则可以使它工作,就像这样-
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Container(
color: Colors.orange,
child: CustomPaint(
painter: BottomCurvePainter(),
),
);
}
}
有人可以解释为什么将容器包装在脚手架中无法正常工作吗?谢谢。
所以,我试图在Flutter中使用CustomPaint小部件在屏幕上绘制一条对角线。从CustomPaint小部件中,我正在调用名为BottomCurvePainter的CustomPainter类。代码...