From 6949525554c66c2680a28b31b305f95bc6211dcc Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Mon, 24 Jan 2022 15:35:12 -0800 Subject: [PATCH] Show keyboard after text input connection restarts (#96541) --- .../lib/src/widgets/editable_text.dart | 1 + .../test/widgets/editable_text_test.dart | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index 9a203c4be0..e69cc1b20a 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -2311,6 +2311,7 @@ class EditableTextState extends State with AutomaticKeepAliveClien final TextStyle style = widget.style; newConnection + ..show() ..setStyle( fontFamily: style.fontFamily, fontSize: style.fontSize, diff --git a/packages/flutter/test/widgets/editable_text_test.dart b/packages/flutter/test/widgets/editable_text_test.dart index 025123a27d..19d1a9bceb 100644 --- a/packages/flutter/test/widgets/editable_text_test.dart +++ b/packages/flutter/test/widgets/editable_text_test.dart @@ -2194,6 +2194,49 @@ void main() { ]))); }); + testWidgets( + 'requesting focus in the onSubmitted callback should keep the onscreen keyboard visible', + (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/95154 . + final Widget widget = MaterialApp( + home: EditableText( + backgroundCursorColor: Colors.grey, + style: Typography.material2018().black.subtitle1!, + cursorColor: Colors.blue, + focusNode: focusNode, + controller: controller, + onSubmitted: (String value) { + focusNode.requestFocus(); + }, + ), + ); + await tester.pumpWidget(widget); + + focusNode.requestFocus(); + await tester.pump(); + + assert(focusNode.hasFocus); + tester.testTextInput.log.clear(); + + // This will attempt to unfocus the field but the onSubmitted callback + // will cancel that. Restart the input connection in this case. + await tester.testTextInput.receiveAction(TextInputAction.done); + expect(tester.testTextInput.log, containsAllInOrder([ + matchesMethodCall('TextInput.clearClient'), + matchesMethodCall('TextInput.setClient'), + matchesMethodCall('TextInput.show'), + ])); + + tester.testTextInput.log.clear(); + // TextInputAction.unspecified does not unfocus the input field by default. + await tester.testTextInput.receiveAction(TextInputAction.unspecified); + expect(tester.testTextInput.log, isNot(containsAllInOrder([ + matchesMethodCall('TextInput.clearClient'), + matchesMethodCall('TextInput.setClient'), + matchesMethodCall('TextInput.show'), + ]))); + }); + testWidgets( 'iOS autocorrection rectangle should appear on demand and dismiss when the text changes or when focus is lost', (WidgetTester tester) async {