eBay / flutter_glove_box

Various eBay tools for Flutter development
BSD 3-Clause "New" or "Revised" License
323 stars 69 forks source link

GoldenBuilder with materialAppWrapper causes Flutter assertion #174

Open mdazy opened 1 year ago

mdazy commented 1 year ago

Actual results

A builder grid test with a simple widget triggers an assert in Flutter if a MaterialApp wrapper is used (e.g. materialAppWrapper):

// this works - although the last line of widgets gets cropped vertically
      final builder = GoldenBuilder.grid(
        columns: 2,
        widthToHeightRatio: 1,
      )..addScenario( /*...*/ );

// this crashes Flutter
    final builder = GoldenBuilder.grid(
      columns: 2,
      widthToHeightRatio: 1,
      wrap: materialAppWrapper(), // also fails with custom MaterialApp wrapping
    )..addScenario( /*...*/ );

The second case causes an assert with this log

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during performLayout():
RenderBox was not laid out: RenderPadding#d67b0 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1966 pos 12: 'hasSize'

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:
  GridView
  GridView:file:///Users/mdazy/.pub-cache/hosted/pub.dev/golden_toolkit-0.15.0/lib/src/golden_builder.dart:132:21

When the exception was thrown, this was the stack:
#2      RenderBox.size (package:flutter/src/rendering/box.dart:1966:12)
#3      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:123:21)
#4      RenderObject.layout (package:flutter/src/rendering/object.dart:2395:7)
#5      RenderBox.layout (package:flutter/src/rendering/box.dart:2386:11)
#6      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:122:14)
#7      RenderObject.layout (package:flutter/src/rendering/object.dart:2395:7)
#8      RenderBox.layout (package:flutter/src/rendering/box.dart:2386:11)
#9      RenderSliverMultiBoxAdaptor.insertAndLayoutChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:491:13)
#10     RenderSliverGrid.performLayout (package:flutter/src/rendering/sliver_grid.dart:635:17)
#11     RenderObject.layout (package:flutter/src/rendering/object.dart:2395:7)
#12     RenderSliverEdgeInsetsPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:139:12)
#13     RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:361:11)
#14     RenderObject.layout (package:flutter/src/rendering/object.dart:2395:7)
#15     RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:534:13)
#16     RenderShrinkWrappingViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1882:12)
#17     RenderShrinkWrappingViewport.performLayout (package:flutter/src/rendering/viewport.dart:1833:20)
#18     RenderObject.layout (package:flutter/src/rendering/object.dart:2395:7)
#19     RenderBox.layout (package:flutter/src/rendering/box.dart:2386:11)
#20     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:122:14)
#21     RenderObject.layout (package:flutter/src/rendering/object.dart:2395:7)
#22     RenderBox.layout (package:flutter/src/rendering/box.dart:2386:11)
#23     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:122:14)
#24     RenderObject.layout (package:flutter/src/rendering/object.dart:2395:7)
[ 125 more frames omitted for brevity ]

Expected results

Flutter version

Flutter 3.10.2 • channel stable • https://github.com/flutter/flutter.git Framework • revision 9cd3d0d9ff (6 weeks ago) • 2023-05-23 20:57:28 -0700 Engine • revision 90fa3ae28f Tools • Dart 3.0.2 • DevTools 2.23.1

Repro

https://github.com/mdazy/golden_builder_assert

Related

https://github.com/flutter/flutter/issues/129902

mdazy commented 1 year ago

I have added a third example in the repository: wrapping the entire build() inside a single MaterialApp appears to work. I'm guessing multiple MaterialApps inside upper-level layout components are a no-go for Flutter.

However, even in that third example I'm still getting overflow/cropping issues. None of the examples are supplying an explicit size - am I wrong in assuming golden_toolkit is supposed to resize the consolidated screenshot as necessary?