Repository: flutter
Issue: [flutter_svg] [Bug] RenderBox was not laid out with SvgPicture
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/697_

Original report by @eximius313 on Apr 21, 2022

When `SvgPicture` is placed inside `FittedBox` like that:

```dart
  @override
  Widget build(final BuildContext context) =>
    Scaffold(
      appBar: AppBar(
        title: Text("Test"),
      ),
      body: Container(
        padding: EdgeInsets.all(20),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Expanded(
              flex: 2,
              child: FittedBox(
                child: SvgPicture.network('https://raw.githubusercontent.com/lipis/flag-icons/main/flags/4x3/gb.svg', width: 200,),
              ),
            )
          ]
        )));
```
then when you `Hot Reload` the app, everything is rendered just fine, without any errors **but** when you perform a `Restart`, then app shows you a lot of errors:

```dart
═══════ Exception caught by rendering library ═════════════════════════════════
The following assertion was thrown during performLayout():
'package:flutter/src/rendering/box.dart': Failed assertion: line 319 pos 12: 'height > 0.0': is not true.
package:flutter/…/rendering/box.dart:319
2

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

The relevant error-causing widget was
FittedBox
lib\…\screens\screen.dart:284
When the exception was thrown, this was the stack
#2      BoxConstraints.constrainSizeAndAttemptToPreserveAspectRatio
package:flutter/…/rendering/box.dart:319
#3      RenderFittedBox.performLayout
package:flutter/…/rendering/proxy_box.dart:2588
#4      RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#5      ChildLayoutHelper.layoutChild
package:flutter/…/rendering/layout_helper.dart:56
#6      RenderFlex._computeSizes
package:flutter/…/rendering/flex.dart:896
#7      RenderFlex.performLayout
package:flutter/…/rendering/flex.dart:931
#8      RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#9      RenderPadding.performLayout
package:flutter/…/rendering/shifted_box.dart:233
#10     RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#11     MultiChildLayoutDelegate.layoutChild
package:flutter/…/rendering/custom_layout.dart:171
#12     _ScaffoldLayout.performLayout
package:flutter/…/material/scaffold.dart:1005
#13     MultiChildLayoutDelegate._callPerformLayout
package:flutter/…/rendering/custom_layout.dart:240
#14     RenderCustomMultiChildLayoutBox.performLayout
package:flutter/…/rendering/custom_layout.dart:403
#15     RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#16     RenderProxyBoxMixin.performLayout
package:flutter/…/rendering/proxy_box.dart:116
#17     RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#18     RenderProxyBoxMixin.performLayout
package:flutter/…/rendering/proxy_box.dart:116
#19     _RenderCustomClip.performLayout
package:flutter/…/rendering/proxy_box.dart:1376
#20     RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#21     RenderProxyBoxMixin.performLayout
package:flutter/…/rendering/proxy_box.dart:116
#22     RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#23     RenderProxyBoxMixin.performLayout
package:flutter/…/rendering/proxy_box.dart:116
#24     RenderObject.layout
#25     RenderProxyBoxMixin.performLayout
package:flutter/…/rendering/proxy_box.dart:116
#26     RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#27     RenderProxyBoxMixin.performLayout
package:flutter/…/rendering/proxy_box.dart:116
#28     RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#29     RenderProxyBoxMixin.performLayout
package:flutter/…/rendering/proxy_box.dart:116
#30     RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#31     RenderProxyBoxMixin.performLayout
package:flutter/…/rendering/proxy_box.dart:116
#32     RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#33     RenderProxyBoxMixin.performLayout
package:flutter/…/rendering/proxy_box.dart:116
#34     RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#35     RenderProxyBoxMixin.performLayout
package:flutter/…/rendering/proxy_box.dart:116
#36     RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#37     RenderOffstage.performLayout
package:flutter/…/rendering/proxy_box.dart:3426
#38     RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#39     RenderProxyBoxMixin.performLayout
package:flutter/…/rendering/proxy_box.dart:116
#40     RenderObject.layout
package:flutter/…/rendering/object.dart:1852
#41     _RenderTheatre.performLayout
package:flutter/…/widgets/overlay.dart:751
#42     RenderObject._layoutWithoutResize
package:flutter/…/rendering/object.dart:1707
#43     PipelineOwner.flushLayout
package:flutter/…/rendering/object.dart:879
#44     RendererBinding.drawFrame
package:flutter/…/rendering/binding.dart:497
#45     WidgetsBinding.drawFrame
package:flutter/…/widgets/binding.dart:883
#46     RendererBinding._handlePersistentFrameCallback
package:flutter/…/rendering/binding.dart:363
#47     SchedulerBinding._invokeFrameCallback
package:flutter/…/scheduler/binding.dart:1145
#48     SchedulerBinding.handleDrawFrame
package:flutter/…/scheduler/binding.dart:1082
#49     SchedulerBinding._handleDrawFrame
package:flutter/…/scheduler/binding.dart:996
#53     _invoke (dart:ui/hooks.dart:150:10)
#54     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)
#55     _drawFrame (dart:ui/hooks.dart:114:31)
(elided 5 frames from class _AssertionError and dart:async)
The following RenderObject was being processed when the exception was fired: RenderFittedBox#99089 relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
RenderObject: RenderFittedBox#99089 relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
    parentData: offset=Offset(0.0, 0.0); flex=2; fit=FlexFit.tight (can use size)
    constraints: BoxConstraints(w=920.0, 0.0<=h<=444.0)
    size: MISSING
    fit: contain
    alignment: Alignment.center
    textDirection: ltr
    child: RenderSemanticsAnnotations#4bc4d relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        parentData: <none> (can use size)
        constraints: BoxConstraints(unconstrained)
        size: Size(200.0, 0.0)
        child: RenderConstrainedBox#cb093 relayoutBoundary=up5 NEEDS-PAINT
            parentData: <none> (can use size)
            constraints: BoxConstraints(unconstrained)
            size: Size(200.0, 0.0)
            additionalConstraints: BoxConstraints(w=200.0, 0.0<=h<=Infinity)
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderFittedBox#99089 relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
package:flutter/…/rendering/box.dart:1
Failed assertion: line 1927 pos 12: 'hasSize'

The relevant error-causing widget was
Row
lib\…\screens\screen.dart:279
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderFlex#820de relayoutBoundary=up2 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
package:flutter/…/rendering/box.dart:1
Failed assertion: line 1927 pos 12: 'hasSize'

The relevant error-causing widget was
Container
═══════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderPadding#eea56 relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
package:flutter/…/rendering/box.dart:1
Failed assertion: line 1927 pos 12: 'hasSize'

The relevant error-causing widget was
Scaffold
lib\…\screens\screen.dart:272
════════════════════════════════════════════════════════════════════════════════
D/EGL_emulation( 7459): app_time_stats: avg=5602.10ms min=747.92ms max=10456.29ms count=2

════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderFittedBox#99089 relayoutBoundary=up3
'package:flutter/src/rendering/box.dart':
package:flutter/…/rendering/box.dart:1
Failed assertion: line 1927 pos 12: 'hasSize'

The relevant error-causing widget was
FittedBox
lib\…\screens\screen.dart:284
════════════════════════════════════════════════════════════════════════════════
```


I think it's a bug with `SvgPicture` because when I use `Text("Foo")` instead of `SvgPicture` - no error happen either with `HotReload` nor `Restart`.

---
Comment by @gabcarneiro on Sep 1, 2022
Same issue here, the layout of the app im working on also has a SvgPicture inside a FittedBox

---
Comment by @gabcarneiro on Sep 1, 2022
> Same issue here, the layout of the app im working on also has a SvgPicture inside a FittedBox

Fixed it by instead of wrapping the SvgPicture inside a FittedBox, i used the `SvgPicture.fit` property. 

From: 
```dart
child: FittedBox(
  fit: BoxFit.scaleDown,
  child: SvgPicture.asset('my.svg'),
),
```

To:
```dart
child: SvgPicture.asset(
  'my.svg',
  fit: BoxFit.scaleDown,
),
```

---
Comment by @PiotrKedra on Jan 11, 2024
Have same problem