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.
When incorrectly implementing a custom InlineSpan, I encountered an assert inside the
positionInlineChildrenfunction with the following message:Looking only at this message, I would think my implementation is correct (5 is indeed greater than 1). However, the logic in the
positionInlineChildrenfunction expects the opposite: the number of boxes must NOT exceed the number of children (childCount).The current message is logically incorrect and misleading for debugging.