Skip to content

Misleading error message in positionInlineChildren assert #182090

Description

@BrainLUX

When incorrectly implementing a custom InlineSpan, I encountered an assert inside the positionInlineChildren function with the following message:

The length of boxes (5) should be greater than childCount (1)

Looking only at this message, I would think my implementation is correct (5 is indeed greater than 1). However, the logic in the positionInlineChildren function expects the opposite: the number of boxes must NOT exceed the number of children (childCount).

  @protected
  void positionInlineChildren(List<ui.TextBox> boxes) {
    RenderBox? child = firstChild;
    for (final box in boxes) {
      if (child == null) {
        assert(
          false,
          'The length of boxes (${boxes.length}) should be greater than childCount ($childCount)',
        );
        return;
      }
      final textParentData = child.parentData! as TextParentData;
      textParentData._offset = Offset(box.left, box.top);
      child = childAfter(child);
    }
    while (child != null) {
      final textParentData = child.parentData! as TextParentData;
      textParentData._offset = null;
      child = childAfter(child);
    }
  }

The current message is logically incorrect and misleading for debugging.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: renderingUI glitches reported at the engine/skia or impeller rendering levelframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions