Skip to content

Fix SplitPane RangeError when child count changes between rebuilds#9822

Open
ishaquehassan wants to merge 4 commits intoflutter:masterfrom
ishaquehassan:fix/9648-splitpane-rangeerror-on-children-count-change
Open

Fix SplitPane RangeError when child count changes between rebuilds#9822
ishaquehassan wants to merge 4 commits intoflutter:masterfrom
ishaquehassan:fix/9648-splitpane-rangeerror-on-children-count-change

Conversation

@ishaquehassan
Copy link
Copy Markdown

@ishaquehassan ishaquehassan commented May 6, 2026

Fixes #9648.

SplitPane cached its fractions list in initState only. When the parent rebuilt the widget with a different number of children (for example, toggling a panel in or out with a collection-if), fractions.length stayed at the old value while widget.minSizes and widget.children shrank. The next layout pass called minSizeForIndex with an index past the end of widget.minSizes and threw RangeError (index): Index out of range: index should be less than 2: 2 from split_pane.dart:126.

This adds didUpdateWidget to _SplitPaneState. When the child count changes, fractions is reset to List.of(widget.initialFractions) so it stays in sync with the new children and minSizes. The existing constructor assertion (children.length == initialFractions.length) already guarantees the new list has the right length, so no extra defensive logic is needed. fractions lost its final modifier to allow the reassignment.

devtools_app_shared is bumped to 0.5.2 and a CHANGELOG entry is added.

Tests

Added two regression tests in split_pane_test.dart under a new rebuilds with a different number of children group:

  • pumps a 3-child SplitPane, then pumps a 2-child SplitPane with the same key path, and asserts no exception is thrown
  • the inverse: 2-child then 3-child

Both tests reproduce the original RangeError on master and pass with the fix.

Note: running the local flutter test against the bundled Flutter SDK currently fails to compile because of an unrelated pre-existing error in flutter/lib/src/widgets/_window_linux.dart (isSizedToContent getter is missing on WindowingOwnerLinux). That failure reproduces on master without this change and is independent of SplitPane. CI should compile against a matching SDK.

Pre-launch Checklist

General checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read the Flutter Style Guide recently, and have followed its advice.
  • I signed the CLA.
  • I updated/added relevant documentation (doc comments with ///).

Issues checklist

Tests checklist

  • I added new tests to check the change I am making...
  • OR there is a reason for not adding tests, which I explained in the PR description.

AI-tooling checklist

  • I did not use any AI tooling in creating this PR.
  • OR I did use AI tooling, and...
    • I read the AI contributions guidelines and agree to follow them.
    • I reviewed all AI-generated code before opening this PR.
    • I understand and am able to discuss the code in this PR.
    • I have verifed the accuracy of any AI-generated text included in the PR description.
    • I commit to verifying the accuracy of any AI-generated code or text that I upload in response to review comments.

Feature-change checklist

  • This PR does not change the DevTools UI or behavior and...
    • I added the release-notes-not-required label or left a comment requesting the label be added.
  • OR this PR does change the DevTools UI or behavior and...
    • I added an entry to packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md.
    • I included before/after screenshots and/or a GIF demo of the new UI to my PR description.
    • I ran the DevTools app locally to manually verify my changes.

build.yaml badge

If you need help, consider asking for help on Discord.

Fixes flutter#9648.

SplitPane cached its fractions list in initState only. When the parent
rebuilt the widget with a different number of children (for example,
toggling a panel via a collection-if), fractions.length stayed at the
old value while widget.minSizes and widget.children shrank, causing
minSizeForIndex to read past the end of widget.minSizes and throw
'RangeError (index): Index out of range: index should be less than 2: 2'
from the layout pass.

This adds didUpdateWidget to _SplitPaneState. When the child count
changes, fractions is reset to List.of(widget.initialFractions) so it
stays in sync with the new children and minSizes. The existing
constructor assertion already guarantees children.length matches
initialFractions.length.

Bumps devtools_app_shared to 0.5.2 with a CHANGELOG entry, and adds
regression tests that pump a 3-child SplitPane and then a 2-child
SplitPane (and vice versa) and assert no exception is thrown.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a RangeError in the SplitPane widget triggered by changes in the number of children during rebuilds. The fix modifies _SplitPaneState to reset the fractions list within didUpdateWidget whenever the child count changes. The devtools_app_shared package version is updated to 0.5.2, and new tests are included to ensure stability when the number of children grows or shrinks. I have no feedback to provide.

Copy link
Copy Markdown
Member

@kenzieschmoll kenzieschmoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a release note entry for this change.

@ishaquehassan ishaquehassan requested a review from a team as a code owner May 7, 2026 19:25
@ishaquehassan ishaquehassan requested review from elliette and removed request for a team May 7, 2026 19:25
@ishaquehassan
Copy link
Copy Markdown
Author

@kenzieschmoll yeah calling a RangeError 'not user facing' was a stretch on my part 😅. Added a General updates entry and corrected the PR body. Pushed.

Comment thread packages/devtools_app_shared/CHANGELOG.md Outdated
Comment thread packages/devtools_app_shared/pubspec.yaml Outdated
Copy link
Copy Markdown
Member

@kenzieschmoll kenzieschmoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a couple more comments regarding the version of devtools_app_shared

@ishaquehassan
Copy link
Copy Markdown
Author

@kenzieschmoll Both bumped to 0.5.2-wip. Thanks for the approve, ready to land 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SplitPane: RangeError when rebuilding with a different number of children

2 participants