diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart index 7e1c94a677..deb41650d2 100644 --- a/packages/flutter/lib/src/rendering/proxy_box.dart +++ b/packages/flutter/lib/src/rendering/proxy_box.dart @@ -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); } } diff --git a/packages/flutter/test/widgets/fitted_box_test.dart b/packages/flutter/test/widgets/fitted_box_test.dart index 709123ca41..76321c8f46 100644 --- a/packages/flutter/test/widgets/fitted_box_test.dart +++ b/packages/flutter/test/widgets/fitted_box_test.dart @@ -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 getLayers() {