Fix RenderCustomPaint intrinsics (#72103)
Make RenderCustomPaint consult its preferred size for intrinsics when it has no child. Currently, it returns 0 for its intrinsics, even if it has a non-zero preferred size.
This commit is contained in:
@@ -487,6 +487,34 @@ class RenderCustomPaint extends RenderProxyBox {
|
||||
/// to change in the next frame.
|
||||
bool willChange;
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicWidth(double height) {
|
||||
if (child == null)
|
||||
return preferredSize.width.isFinite ? preferredSize.width : 0;
|
||||
return super.computeMinIntrinsicWidth(height);
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicWidth(double height) {
|
||||
if (child == null)
|
||||
return preferredSize.width.isFinite ? preferredSize.width : 0;
|
||||
return super.computeMaxIntrinsicWidth(height);
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicHeight(double width) {
|
||||
if (child == null)
|
||||
return preferredSize.height.isFinite ? preferredSize.height : 0;
|
||||
return super.computeMinIntrinsicHeight(width);
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicHeight(double width) {
|
||||
if (child == null)
|
||||
return preferredSize.height.isFinite ? preferredSize.height : 0;
|
||||
return super.computeMaxIntrinsicHeight(width);
|
||||
}
|
||||
|
||||
@override
|
||||
void attach(PipelineOwner owner) {
|
||||
super.attach(owner);
|
||||
|
||||
@@ -198,4 +198,20 @@ void main() {
|
||||
expect(() => CustomPaint(isComplex: true), throwsAssertionError);
|
||||
expect(() => CustomPaint(willChange: true), throwsAssertionError);
|
||||
});
|
||||
|
||||
test('RenderCustomPaint consults preferred size for intrinsics when it has no child', () {
|
||||
final RenderCustomPaint inner = RenderCustomPaint(preferredSize: const Size(20, 30));
|
||||
expect(inner.getMinIntrinsicWidth(double.infinity), 20);
|
||||
expect(inner.getMaxIntrinsicWidth(double.infinity), 20);
|
||||
expect(inner.getMinIntrinsicHeight(double.infinity), 30);
|
||||
expect(inner.getMaxIntrinsicHeight(double.infinity), 30);
|
||||
});
|
||||
|
||||
test('RenderCustomPaint does not return infinity for its intrinsics', () {
|
||||
final RenderCustomPaint inner = RenderCustomPaint(preferredSize: const Size.square(double.infinity));
|
||||
expect(inner.getMinIntrinsicWidth(double.infinity), 0);
|
||||
expect(inner.getMaxIntrinsicWidth(double.infinity), 0);
|
||||
expect(inner.getMinIntrinsicHeight(double.infinity), 0);
|
||||
expect(inner.getMaxIntrinsicHeight(double.infinity), 0);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user