Column's child's CustomPainter's size become (0, 0).
1) When we just used CustomPaint and CustomPainter, the size we expected was passed to CustomPainter, which is rendered as expected.
2) When we used CustomPaint and CustomPainter as Stack's children, the size we expected was not passed to CustomPainter.
3) But when we used it as SizedBox.expand's children, the size we expected was passed to CustomPainter and it was rendered.
4) When we used CustomPaint and CustomPainter as Column's children, the size we expected was not passed to CustomPainter. We are investigating ways to solve it.
5) However, it is either 0.0 or infinite in height. We want it to just expand to a good size.
import 'package:flutter/material.dart';
class TestWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
// 1) OK Size(360.0, 640.0)
// return CustomPaint(
// painter: TestPainter(),
// );
// 2) NG Size(0.0, 0.0)
// return Stack(
// children: <Widget>[
// CustomPaint(
// painter: TestPainter(),
// ),
// ],
// );
// 3) OK Size(360.0, 640.0)
// return Stack(
// children: <Widget>[
// SizedBox.expand(
// child: CustomPaint(
// painter: TestPainter(),
// ),
// ),
// ],
// );
// 4)5) NG BoxConstraints forces an infinite height.
// return Column(
// children: <Widget>[
// SizedBox.expand(
// child: CustomPaint(
// painter: TestPainter(),
// ),
// ),
// Text('test'),
// ],
// );
// 4)5) NG Size(0.0, 0.0)
// return Column(
// children: <Widget>[
// SizedBox(
// child: CustomPaint(
// painter: TestPainter(),
// ),
// ),
// Text('test'),
// ],
// );
// 4)5) Size(360.0, 0.0)
// return Column(
// children: <Widget>[
// SizedBox(
// width: double.infinity,
// child: CustomPaint(
// painter: TestPainter(),
// ),
// ),
// Text('test'),
// ],
// );
}
}
class TestPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
print(size);
Paint p = Paint();
p.color = Color.fromARGB(0xff, 0xff, 0x00, 0x00);
Rect rect = Rect.fromLTWH(0, 0, size.width, size.height);
canvas.drawRect(rect, p);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
We expect CustomPaint and CustomPainter to be expanded to the appropriate size and that size will be passed to CustomPainter.