Fix null child for FittedBox (#86662)

This commit is contained in:
Michael Goderbauer
2021-07-19 11:01:04 -07:00
committed by GitHub
parent 1edd9126ed
commit e9c1c1627a
2 changed files with 31 additions and 13 deletions

View File

@@ -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);
}
}

View File

@@ -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() {