Unverified Commit e9c1c162 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Fix null child for FittedBox (#86662)

parent 1edd9126
......@@ -2651,21 +2651,21 @@ class RenderFittedBox extends RenderProxyBox {
@override
void paint(PaintingContext context, Offset offset) {
if (size.isEmpty || child!.size.isEmpty)
if (child == null || size.isEmpty || child!.size.isEmpty)
return;
_updatePaintData();
if (child != null) {
if (_hasVisualOverflow! && clipBehavior != Clip.none)
layer = context.pushClipRect(
needsCompositing,
offset,
Offset.zero & size,
_paintChildWithTransform,
oldLayer: layer is ClipRectLayer ? layer! as ClipRectLayer : null,
clipBehavior: clipBehavior,
);
else
layer = _paintChildWithTransform(context, offset);
assert(child != null);
if (_hasVisualOverflow! && clipBehavior != Clip.none) {
layer = context.pushClipRect(
needsCompositing,
offset,
Offset.zero & size,
_paintChildWithTransform,
oldLayer: layer is ClipRectLayer ? layer! as ClipRectLayer : null,
clipBehavior: clipBehavior,
);
} else {
layer = _paintChildWithTransform(context, offset);
}
}
......
......@@ -589,6 +589,24 @@ void main() {
expect(outsideBox.size.height, 50.0);
});
testWidgets('FittedBox without child does not throw', (WidgetTester tester) async {
await tester.pumpWidget(
const Center(
child: SizedBox(
width: 200.0,
height: 200.0,
child: FittedBox(),
),
),
);
expect(find.byType(FittedBox), findsOneWidget);
// Tapping it also should not throw.
await tester.tap(find.byType(FittedBox), warnIfMissed: false);
expect(tester.takeException(), isNull);
});
}
List<Type> getLayers() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment