Skip to content

Flutter framework internal error thrown when removing second-to-last child of IndexedStack #165840

@driftwoodstudio

Description

@driftwoodstudio

Steps to reproduce

Happened after setting State that should cause IndexedStack to re-render and discover one less child than previous render cycle. Note that moving from 4 to 3 to 2 children this way worked fine, but reliably throws this error when moving from State that will find 2 children to State that will find one child.

Console output was:

════════ Exception caught by rendering library ═════════════════════════════════
The following assertion was thrown during paint():
'package:flutter/src/rendering/stack.dart': Failed assertion: line 799 pos 12: 'firstChild == null || child != null': 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:
    IndexedStack IndexedStack:file:///F:/work/FractalOutliner/repo/FractalOutliner/flutter_app/fractal_outliner/lib/view/editor_stack/editor_panel_stack.dart:18:16

When the exception was thrown, this was the stack:
#2      RenderIndexedStack._childAtIndex (package:flutter/src/rendering/stack.dart:799:12)
#3      RenderIndexedStack.paintStack (package:flutter/src/rendering/stack.dart:859:39)
#4      RenderStack.paint (package:flutter/src/rendering/stack.dart:720:7)
#5      RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3371:7)
#6      PaintingContext.paintChild (package:flutter/src/rendering/object.dart:260:13)
#7      RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:3360:15)
#8      RenderFlex.paint (package:flutter/src/rendering/flex.dart:1315:7)
#9      RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3371:7)
#10     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:260:13)
#11     RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:3360:15)
#12     RenderFlex.paint (package:flutter/src/rendering/flex.dart:1315:7)
#13     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3371:7)
#14     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:260:13)
#15     RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:3360:15)
#16     RenderStack.paintStack (package:flutter/src/rendering/stack.dart:704:5)
#17     RenderStack.paint (package:flutter/src/rendering/stack.dart:720:7)
#18     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3371:7)
#19     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:260:13)
#20     RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:3360:15)
#21     RenderCustomMultiChildLayoutBox.paint (package:flutter/src/rendering/custom_layout.dart:424:5)
#22     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3371:7)
#23     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:260:13)
#24     RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:13)
#25     _RenderInkFeatures.paint (package:flutter/src/material/material.dart:632:11)
#26     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3371:7)
#27     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:260:13)
#28     RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:13)
#29     RenderPhysicalModel.paint.<anonymous closure> (package:flutter/src/rendering/proxy_box.dart:2083:15)
#30     PaintingContext.pushClipRRect (package:flutter/src/rendering/object.dart:610:14)
#31     RenderPhysicalModel.paint (package:flutter/src/rendering/proxy_box.dart:2070:21)
#32     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3371:7)
#33     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:260:13)
#34     RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:13)
#35     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3371:7)
#36     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:260:13)
#37     RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:13)
#38     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3371:7)
#39     PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:175:11)
#40     PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:120:5)
#41     PipelineOwner.flushPaint (package:flutter/src/rendering/object.dart:1251:31)
#42     PipelineOwner.flushPaint (package:flutter/src/rendering/object.dart:1261:15)
#43     RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:618:23)
#44     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1231:13)
#45     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:482:5)
#46     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1442:15)
#47     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1355:9)
#48     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1208:5)
#49     _invoke (dart:ui/hooks.dart:316:13)
#50     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:428:5)
#51     _drawFrame (dart:ui/hooks.dart:288:31)
(elided 2 frames from class _AssertionError)

The following RenderObject was being processed when the exception was fired: RenderIndexedStack#2f9cd relayoutBoundary=up4
    needs compositing
    parentData: offset=Offset(0.0, 35.0); flex=1; fit=FlexFit.tight (can use size)
    constraints: BoxConstraints(0.0<=w<=785.3, h=647.7)
    size: Size(785.3, 647.7)
    alignment: AlignmentDirectional.topStart
    textDirection: ltr
    fit: loose
    index: 1
    child 1: _RenderVisibility#c03cf relayoutBoundary=up5 NEEDS-PAINT
        needs compositing
        parentData: not positioned; offset=Offset(0.0, 0.0) (can use size)
        constraints: BoxConstraints(0.0<=w<=785.3, 0.0<=h<=647.7)
        size: Size(785.3, 647.7)
        child: RenderIgnorePointer#444c8 relayoutBoundary=up6 NEEDS-PAINT
            needs compositing
            parentData: <none> (can use size)
            constraints: BoxConstraints(0.0<=w<=785.3, 0.0<=h<=647.7)
            size: Size(785.3, 647.7)
            ignoring: false
            ignoringSemantics: null
            child: RenderStack#1a31a relayoutBoundary=up7 NEEDS-PAINT
                needs compositing
                parentData: <none> (can use size)
                constraints: BoxConstraints(0.0<=w<=785.3, 0.0<=h<=647.7)
                size: Size(785.3, 647.7)
                alignment: AlignmentDirectional.topStart
                textDirection: ltr
                fit: loose
                child 1: RenderFlex#7b1b6 relayoutBoundary=up8 NEEDS-PAINT
                    needs compositing
                    parentData: not positioned; offset=Offset(0.0, 0.0) (can use size)
                    constraints: BoxConstraints(0.0<=w<=785.3, 0.0<=h<=647.7)
                    size: Size(785.3, 647.7)
                    direction: horizontal
                    mainAxisAlignment: start
                    mainAxisSize: max
                    crossAxisAlignment: start
                    textDirection: ltr
                    verticalDirection: down
                    spacing: 0.0
RenderObject: RenderIndexedStack#2f9cd relayoutBoundary=up4
    needs compositing
    parentData: offset=Offset(0.0, 35.0); flex=1; fit=FlexFit.tight (can use size)
    constraints: BoxConstraints(0.0<=w<=785.3, h=647.7)
    size: Size(785.3, 647.7)
    alignment: AlignmentDirectional.topStart
    textDirection: ltr
    fit: loose
    index: 1
    child 1: _RenderVisibility#c03cf relayoutBoundary=up5 NEEDS-PAINT
        needs compositing
        parentData: not positioned; offset=Offset(0.0, 0.0) (can use size)
        constraints: BoxConstraints(0.0<=w<=785.3, 0.0<=h<=647.7)
        size: Size(785.3, 647.7)
        child: RenderIgnorePointer#444c8 relayoutBoundary=up6 NEEDS-PAINT
            needs compositing
            parentData: <none> (can use size)
            constraints: BoxConstraints(0.0<=w<=785.3, 0.0<=h<=647.7)
            size: Size(785.3, 647.7)
            ignoring: false
            ignoringSemantics: null
            child: RenderStack#1a31a relayoutBoundary=up7 NEEDS-PAINT
                needs compositing
                parentData: <none> (can use size)
                constraints: BoxConstraints(0.0<=w<=785.3, 0.0<=h<=647.7)
                size: Size(785.3, 647.7)
                alignment: AlignmentDirectional.topStart
                textDirection: ltr
                fit: loose
                child 1: RenderFlex#7b1b6 relayoutBoundary=up8 NEEDS-PAINT
                    needs compositing
                    parentData: not positioned; offset=Offset(0.0, 0.0) (can use size)
                    constraints: BoxConstraints(0.0<=w<=785.3, 0.0<=h<=647.7)
                    size: Size(785.3, 647.7)
                    direction: horizontal
                    mainAxisAlignment: start
                    mainAxisSize: max
                    crossAxisAlignment: start
                    textDirection: ltr
                    verticalDirection: down
                    spacing: 0.0
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gestures library ══════════════════════════════════
'package:flutter/src/rendering/stack.dart': Failed assertion: line 799 pos 12: 'firstChild == null || child != null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gestures library ══════════════════════════════════
'package:flutter/src/rendering/stack.dart': Failed assertion: line 799 pos 12: 'firstChild == null || child != null': is not true.
════════════════════════════════════════════════════════════════════════════════


Expected results

Render with the one remaining child

Actual results

Error thrown as above

Code sample

Code sample

The code for this is too complex in terms of context for me to spend my time trying to extract a reproducible example. Framework threw the error, asked me to report it, I'm reporting it.

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

NOTE: this is for MacOS/Windows application, so issues with Android tool chain and Chrome are irrelevant. Run platform was Windows.

PS F:\work\FractalOutliner\repo\FractalOutliner\flutter_app\fractal_outliner> flutter doctor -v
[√] Flutter (Channel stable, 3.29.0, on Microsoft Windows [Version 10.0.19045.5608], locale en-US) [281ms]
• Flutter version 3.29.0 on channel stable at F:\dev\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 35c388a (6 weeks ago), 2025-02-10 12:48:41 -0800
• Engine revision f73bfc4
• Dart version 3.7.0
• DevTools version 2.42.2

[√] Windows Version (10 Home 64-bit, 22H2, 2009) [895ms]

[X] Android toolchain - develop for Android devices [93ms]
X Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/to/windows-android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
flutter config --android-sdk to update to that location.

[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe) [77ms]
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.13.0) [76ms]
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.13.35806.99
• Windows 10 SDK version 10.0.22621.0

[!] Android Studio (not installed) [11ms]
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/to/windows-android-setup for detailed instructions).

[√] Connected device (2 available) [54ms]
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19045.5608]
• Edge (web) • edge • web-javascript • Microsoft Edge 134.0.3124.72

[√] Network resources [528ms]
• All expected network resources are available.

! Doctor found issues in 3 categories.
PS F:\work\FractalOutliner\repo\FractalOutliner\flutter_app\fractal_outliner>

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: crashStack traces logged to the consoleframeworkflutter/packages/flutter repository. See also f: labels.needs repro infoAutomated crash report whose cause isn't yet knownr: 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