Skip to content

fix: make _selectedRects growable to avoid 'Cannot add to a fixed-length list'#2736

Open
Mounix99 wants to merge 2 commits into
singerdmx:masterfrom
Mounix99:fix/selected-rects-fixed-length-list
Open

fix: make _selectedRects growable to avoid 'Cannot add to a fixed-length list'#2736
Mounix99 wants to merge 2 commits into
singerdmx:masterfrom
Mounix99:fix/selected-rects-fixed-length-list

Conversation

@Mounix99
Copy link
Copy Markdown

@Mounix99 Mounix99 commented Jun 2, 2026

Description

RenderEditableTextLine.paint appends a TextBox to _selectedRects when a selection contains an empty line:

https://github.com/singerdmx/flutter-quill/blob/master/lib/src/editor/widgets/text/text_line.dart#L1436

_selectedRects is assigned from RenderBox.getBoxesForSelection(...), which can return a fixed-length / unmodifiable list. The subsequent .add(...) then throws:

UnsupportedError: Unsupported operation: Cannot add to a fixed-length list
  at FixedLengthListMixin.add (list.dart)
  at RenderEditableTextLine.paint (text_line.dart:1436)

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

  • Bug fix (non-breaking change which fixes an issue)

Mounix99 added 2 commits June 2, 2026 18:14
…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.
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.

1 participant