Skip to content

RenderTwoDimensionalViewport.buildOrObtainChildFor throws assertion failure for a valid vicinity #141101

@Amir-P

Description

@Amir-P

Steps to reproduce

  1. Run the example
  2. Press on FAB
  3. 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

Code sample

https://dartpad.dev/?id=2c4cc823007d1dc0a9727be611e62f2c

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.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: error messageError messages from the Flutter frameworkf: scrollingViewports, list views, slivers, etc.found in release: 3.16Found to occur in 3.16found in release: 3.18Found to occur in 3.18frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions