Skip to content

Fix SelectableRegion crash when the selection starts in a scrollable child but does not select anything initially#184164

Closed
Renzo-Olivares wants to merge 10000 commits into
flutter:masterfrom
Renzo-Olivares:selection-starts-in-scrollable-fix
Closed

Fix SelectableRegion crash when the selection starts in a scrollable child but does not select anything initially#184164
Renzo-Olivares wants to merge 10000 commits into
flutter:masterfrom
Renzo-Olivares:selection-starts-in-scrollable-fix

Conversation

@Renzo-Olivares

@Renzo-Olivares Renzo-Olivares commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #115787

Before this change sometimes when starting a selection gesture such as a long press drag or a double tap drag directly on the empty padding of a Scrollable the selection may not be set initially because there was nothing to select in the empty padding. This caused a crash when receiving subsequent edge update events because we believe the selection starts in the scrollable but we do not have any selection edges set.

To fix this I made _selectionStartsInScrollable nullable, this way a subsequent selection edge will not try to set _selectionStartsInScrollable again if it has already been set removing the need for the assert. handleSelectionEdgeUpdate previously assumed that if the cached edges were not set then we should set _selectionStartsInScrollable, the assert was used to verify that _selectionStartsInScrollable was false i.e. had not been set/changed from its initial value. By making _selectionStartsInScrollable nullable we can ensure a subsequent edge update event does not re-set the value if it has already been set previously.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

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

Labels

CICD Run CI/CD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Selection] How To Avoid '!_selectionStartsInScrollable': is not true. assertion when using SelectionArea with scrollable widget.