fix: make _selectedRects growable to avoid 'Cannot add to a fixed-length list'#2736
Open
Mounix99 wants to merge 2 commits into
Open
fix: make _selectedRects growable to avoid 'Cannot add to a fixed-length list'#2736Mounix99 wants to merge 2 commits into
Mounix99 wants to merge 2 commits into
Conversation
…gth list' RenderEditableTextLine.paint appends a TextBox to _selectedRects for empty lines contained by a selection. _selectedRects is assigned from RenderBox.getBoxesForSelection, which can return a fixed-length/unmodifiable list, so the subsequent .add throws: UnsupportedError: Cannot add to a fixed-length list at FixedLengthListMixin.add during paint(). Convert the result to a growable list with .toList() before mutating it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
RenderEditableTextLine.paintappends aTextBoxto_selectedRectswhen a selection contains an empty line:https://github.com/singerdmx/flutter-quill/blob/master/lib/src/editor/widgets/text/text_line.dart#L1436
_selectedRectsis assigned fromRenderBox.getBoxesForSelection(...), which can return a fixed-length / unmodifiable list. The subsequent.add(...)then throws:This is a
thrown during paint()crash, so it takes down the frame. We observed it in production (Flutter 3.41.2 / Dart 3.11, both Android and iOS) on a screen with a Quill editor. Repro: place the caret selection so that it spans an empty line within the document.Fix
Convert the result of
getBoxesForSelection(...)to a growable list with.toList()before any.add(...). One-line change; no behavioral difference other than the list now being mutable as the code already assumes.Type of change