fixes iphone force press keybaord select crashes (#36698)
diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart
index c821bb2..27c1b91 100644
--- a/packages/flutter/lib/src/widgets/editable_text.dart
+++ b/packages/flutter/lib/src/widgets/editable_text.dart
@@ -1145,8 +1145,11 @@
}
break;
case FloatingCursorDragState.End:
- _floatingCursorResetController.value = 0.0;
- _floatingCursorResetController.animateTo(1.0, duration: _floatingCursorResetTime, curve: Curves.decelerate);
+ // We skip animation if no update has happened.
+ if (_lastTextPosition != null && _lastBoundedOffset != null) {
+ _floatingCursorResetController.value = 0.0;
+ _floatingCursorResetController.animateTo(1.0, duration: _floatingCursorResetTime, curve: Curves.decelerate);
+ }
break;
}
}
diff --git a/packages/flutter/test/widgets/editable_text_cursor_test.dart b/packages/flutter/test/widgets/editable_text_cursor_test.dart
index 08c2d0f..23292da 100644
--- a/packages/flutter/test/widgets/editable_text_cursor_test.dart
+++ b/packages/flutter/test/widgets/editable_text_cursor_test.dart
@@ -509,6 +509,50 @@
expect(controller.selection.baseOffset, 10);
}, skip: isBrowser);
+ testWidgets('Updating the floating cursor can end without update', (WidgetTester tester) async {
+ const String text = 'hello world this is fun and cool and awesome!';
+ controller.text = text;
+ final FocusNode focusNode = FocusNode();
+
+ await tester.pumpWidget(
+ MediaQuery(
+ data: const MediaQueryData(devicePixelRatio: 1),
+ child: Directionality(
+ textDirection: TextDirection.ltr,
+ child: FocusScope(
+ node: focusScopeNode,
+ autofocus: true,
+ child: EditableText(
+ backgroundCursorColor: Colors.grey,
+ controller: controller,
+ focusNode: focusNode,
+ style: textStyle,
+ cursorColor: cursorColor,
+ ),
+ ),
+ ),
+ ),
+ );
+
+ await tester.tap(find.byType(EditableText));
+ final RenderEditable renderEditable = findRenderEditable(tester);
+ renderEditable.selection = const TextSelection(baseOffset: 29, extentOffset: 29);
+
+ expect(controller.selection.baseOffset, 29);
+
+ final EditableTextState editableTextState = tester.firstState(find.byType(EditableText));
+ editableTextState.updateFloatingCursor(RawFloatingCursorPoint(state: FloatingCursorDragState.Start));
+
+ expect(controller.selection.baseOffset, 29);
+
+ editableTextState.updateFloatingCursor(RawFloatingCursorPoint(state: FloatingCursorDragState.End));
+
+ await tester.pumpAndSettle();
+ // The cursor did not change.
+ expect(controller.selection.baseOffset, 29);
+ expect(tester.takeException(), null);
+ }, skip: isBrowser);
+
// Regression test for https://github.com/flutter/flutter/pull/30475.
testWidgets('Trying to select with the floating cursor does not crash', (WidgetTester tester) async {
const String text = 'hello world this is fun and cool and awesome!';