Repository navigation
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: error messageError messages from the Flutter frameworkError messages from the Flutter frameworkf: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 3.16Found to occur in 3.16Found to occur in 3.16found in release: 3.18Found to occur in 3.18Found to occur in 3.18frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Steps to reproduce
- Run the example
- Press on FAB
- Press again on FAB
Expected results
You should see the initial widgets on screen since pressing on FAB for second time returns to the initial state.
Actual results
Nothing renders on screen and you'll get an exception log in console due to assertion failure in RenderTwoDimensionalViewport.parentDataOf
Code sample
Logs
Logs
════════ Exception caught by rendering library ═════════════════════════════════
The following assertion was thrown during performLayout():
'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 783 pos 12: '_children.containsValue(child)': is not true.
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.yml
The relevant error-causing widget was:
TwoDimensionalGridViewport TwoDimensionalGridViewport:file:///main.dart:127:12
When the exception was thrown, this was the stack:
#2 RenderTwoDimensionalViewport.parentDataOf (package:flutter/src/widgets/two_dimensional_viewport.dart:783:12)
#3 RenderTwoDimensionalViewport._moveChild (package:flutter/src/widgets/two_dimensional_viewport.dart:1630:62)
#4 _TwoDimensionalViewportElement.moveRenderObjectChild (package:flutter/src/widgets/two_dimensional_viewport.dart:265:18)
#5 RenderObjectElement.updateSlot (package:flutter/src/widgets/framework.dart:6542:35)
#6 Element.updateSlotForChild.visit (package:flutter/src/widgets/framework.dart:4153:15)
#7 Element.updateSlotForChild.visit (package:flutter/src/widgets/framework.dart:4156:9)
#8 Element.updateSlotForChild.visit (package:flutter/src/widgets/framework.dart:4156:9)
#9 Element.updateSlotForChild.visit (package:flutter/src/widgets/framework.dart:4156:9)
#10 Element.updateSlotForChild (package:flutter/src/widgets/framework.dart:4159:5)
#11 Element.updateChild (package:flutter/src/widgets/framework.dart:3799:11)
#12 _TwoDimensionalViewportElement._buildChild.<anonymous closure> (package:flutter/src/widgets/two_dimensional_viewport.dart:313:33)
#13 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2835:19)
#14 _TwoDimensionalViewportElement._buildChild (package:flutter/src/widgets/two_dimensional_viewport.dart:307:12)
#15 RenderTwoDimensionalViewport.buildOrObtainChildFor.<anonymous closure> (package:flutter/src/widgets/two_dimensional_viewport.dart:1427:23)
#16 RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:2657:59)
#17 PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:1071:15)
#18 RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:2657:14)
#19 RenderTwoDimensionalViewport.buildOrObtainChildFor (package:flutter/src/widgets/two_dimensional_viewport.dart:1426:7)
#20 RenderTwoDimensionalGridViewport.layoutChildSequence (package:example/main.dart:227:34)
#21 RenderTwoDimensionalViewport.performLayout (package:flutter/src/widgets/two_dimensional_viewport.dart:1252:5)
#22 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:2385:7)
#23 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1025:18)
#24 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1038:15)
#25 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:591:23)
#26 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:986:13)
#27 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:457:5)
#28 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1325:15)
#29 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1255:9)
#30 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1113:5)
#31 _invoke (dart:ui/hooks.dart:312:13)
#32 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:383:5)
#33 _drawFrame (dart:ui/hooks.dart:283:31)
(elided 2 frames from class _AssertionError)
The following RenderObject was being processed when the exception was fired: RenderTwoDimensionalGridViewport#9d954 NEEDS-LAYOUT
needs compositing
parentData: <none> (can use size)
constraints: BoxConstraints(0.0<=w<=984.0, 0.0<=h<=691.0)
layer: OffsetLayer#dc1bd
engine layer: OffsetEngineLayer#3c122
handles: 2
offset: Offset(0.0, 56.0)
size: Size(984.0, 691.0)
(xIndex: 1, yIndex: 1): RenderRepaintBoundary#71f4f NEEDS-PAINT
needs compositing
parentData: vicinity=(xIndex: 1, yIndex: 1); layoutOffset=Offset(200.0, 200.0); paintOffset=Offset(0.0, 0.0); visible - paintExtent=Size(200.0, 200.0);
constraints: BoxConstraints(0.0<=w<=984.0, 0.0<=h<=691.0)
layer: OffsetLayer#8295b
engine layer: OffsetEngineLayer#415f8
handles: 2
offset: Offset(0.0, 0.0)
size: Size(200.0, 200.0)
metrics: 66.7% useful (1 bad vs 2 good)
diagnosis: insufficient data to draw conclusion (less than five repaints)
child: RenderConstrainedBox#f153a relayoutBoundary=up1 NEEDS-PAINT
parentData: <none> (can use size)
constraints: BoxConstraints(0.0<=w<=984.0, 0.0<=h<=691.0)
size: Size(200.0, 200.0)
additionalConstraints: BoxConstraints(w=200.0, h=200.0)
child: _RenderColoredBox#e6003 NEEDS-PAINT
parentData: <none> (can use size)
constraints: BoxConstraints(w=200.0, h=200.0)
size: Size(200.0, 200.0)
behavior: opaque
child: RenderPositionedBox#d4659
parentData: <none> (can use size)
constraints: BoxConstraints(w=200.0, h=200.0)
size: Size(200.0, 200.0)
alignment: Alignment.center
textDirection: ltr
widthFactor: expand
heightFactor: expand
RenderObject: RenderTwoDimensionalGridViewport#9d954 NEEDS-LAYOUT
needs compositing
parentData: <none> (can use size)
constraints: BoxConstraints(0.0<=w<=984.0, 0.0<=h<=691.0)
layer: OffsetLayer#dc1bd
engine layer: OffsetEngineLayer#3c122
handles: 2
offset: Offset(0.0, 56.0)
size: Size(984.0, 691.0)
(xIndex: 1, yIndex: 1): RenderRepaintBoundary#71f4f NEEDS-PAINT
needs compositing
parentData: vicinity=(xIndex: 1, yIndex: 1); layoutOffset=Offset(200.0, 200.0); paintOffset=Offset(0.0, 0.0); visible - paintExtent=Size(200.0, 200.0);
constraints: BoxConstraints(0.0<=w<=984.0, 0.0<=h<=691.0)
layer: OffsetLayer#8295b
engine layer: OffsetEngineLayer#415f8
handles: 2
offset: Offset(0.0, 0.0)
size: Size(200.0, 200.0)
metrics: 66.7% useful (1 bad vs 2 good)
diagnosis: insufficient data to draw conclusion (less than five repaints)
child: RenderConstrainedBox#f153a relayoutBoundary=up1 NEEDS-PAINT
parentData: <none> (can use size)
constraints: BoxConstraints(0.0<=w<=984.0, 0.0<=h<=691.0)
size: Size(200.0, 200.0)
additionalConstraints: BoxConstraints(w=200.0, h=200.0)
child: _RenderColoredBox#e6003 NEEDS-PAINT
parentData: <none> (can use size)
constraints: BoxConstraints(w=200.0, h=200.0)
size: Size(200.0, 200.0)
behavior: opaque
child: RenderPositionedBox#d4659
parentData: <none> (can use size)
constraints: BoxConstraints(w=200.0, h=200.0)
size: Size(200.0, 200.0)
alignment: Alignment.center
textDirection: ltr
widthFactor: expand
heightFactor: expand
════════════════════════════════════════════════════════════════════════════════Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.16.1, on macOS 14.2.1 23C71 darwin-arm64, locale
en-US)
• Flutter version 3.16.1 on channel stable at /flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 7f20e5d18c (6 weeks ago), 2023-11-27 09:47:30 -0800
• Engine revision 22b600f240
• Dart version 3.2.1
• DevTools version 2.28.3Reacted by Andrew Ares
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: error messageError messages from the Flutter frameworkError messages from the Flutter frameworkf: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 3.16Found to occur in 3.16Found to occur in 3.16found in release: 3.18Found to occur in 3.18Found to occur in 3.18frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Activity
[-]Two dimensional viewport buildOrObtainChildFor throws assertion failure for a valid vicinity[/-][+]RenderTwoDimensionalViewport.buildOrObtainChildFor throws assertion failure for a valid vicinity[/+]danagbemava-nc commentedon Jan 9, 2024
Reproducible using the code sample provided in the dartpad shared above (pasted below for easy access).
code sample
flutter doctor -v
Amir-P commentedon Jan 9, 2024
Doing some investigation, I found that the root of this issue is the way
_moveChildimplemented._moveChildassigns the child in_childrenmap from "old key" to "new key" causing the child occupying the "new key" being removed from_children, and therefore future calls to get that forgotten child's parentData will fail due to an assertion inparentDataOf. I think the assertion inparentDataOfis unnecessary and it can be removed. WDYT? @Piinks @danagbemava-ncflutter/packages/flutter/lib/src/widgets/two_dimensional_viewport.dart
Lines 1629 to 1638 in 5f17bad
flutter/packages/flutter/lib/src/widgets/two_dimensional_viewport.dart
Lines 782 to 785 in 5f17bad
Piinks commentedon Jan 10, 2024
Thanks for looking into this. I think the assertion should stay but also maybe it should include those that are being kept alive, and those that are currently in the orphan list?
I wonder if this is something that would be fixed by #130754
One dimensional scrolling supports this with the findChildIndexCallback for when children have been reordered.
Amir-P commentedon Jan 13, 2024
According to my tests 2D foundation is working fine for reordering and the only problem is with the assertion in
parentDataOfwhich can be fixed by including checks for debug orphans andkeepAlivebucket. I will open a PR in a few minutes. @PiinksFix assertion failure when reordering two dimensional children (#141504)
github-actions commentedon Feb 12, 2024
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.