Remove an assert with false positives (#148795)

Fixes https://github.com/flutter/flutter/issues/110343.

This is not an important piece of guardrail and the iOS embedder only expects best-effort results anyways.
This commit is contained in:
LongCatIsLooong
2024-05-22 14:25:31 -07:00
committed by GitHub
parent b2eda0624a
commit d57ea48ca1
2 changed files with 31 additions and 1 deletions

View File

@@ -4494,7 +4494,6 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
Rect? composingRect = renderEditable.getRectForComposingRange(composingRange);
// Send the caret location instead if there's no marked text yet.
if (composingRect == null) {
assert(!composingRange.isValid || composingRange.isCollapsed);
final int offset = composingRange.isValid ? composingRange.start : 0;
composingRect = renderEditable.getLocalRectForCaret(TextPosition(offset: offset));
}

View File

@@ -17548,6 +17548,37 @@ void main() {
const TextSelection.collapsed(offset: 17, affinity: TextAffinity.upstream),
);
});
testWidgets('Composing region can truncate grapheme', (WidgetTester tester) async {
await tester.pumpWidget(
MediaQuery(
data: const MediaQueryData(),
child: Directionality(
textDirection: TextDirection.ltr,
child: EditableText(
autofocus: true,
backgroundCursorColor: Colors.grey,
controller: controller,
focusNode: focusNode,
style: textStyle,
cursorColor: cursorColor,
),
),
),
);
await tester.pumpAndSettle();
assert(focusNode.hasFocus);
controller.value = const TextEditingValue(
text: '',
selection: TextSelection(baseOffset: 1, extentOffset: 2),
composing: TextSelection(baseOffset: 1, extentOffset: 2),
);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
});
}
class UnsettableController extends TextEditingController {