diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index b1ef6e1973..b341e632bb 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -1409,6 +1409,7 @@ class EditableTextState extends State with AutomaticKeepAliveClien keyboardAppearance: widget.keyboardAppearance, ), ); + _textInputConnection.show(); _updateSizeAndTransform(); final TextStyle style = widget.style; @@ -1421,8 +1422,9 @@ class EditableTextState extends State with AutomaticKeepAliveClien textAlign: widget.textAlign, ) ..setEditingState(localValue); + } else { + _textInputConnection.show(); } - _textInputConnection.show(); } void _closeInputConnectionIfNeeded() { diff --git a/packages/flutter/test/widgets/editable_text_test.dart b/packages/flutter/test/widgets/editable_text_test.dart index 932ecb0f77..1fda2aa1c4 100644 --- a/packages/flutter/test/widgets/editable_text_test.dart +++ b/packages/flutter/test/widgets/editable_text_test.dart @@ -3413,6 +3413,45 @@ void main() { throwsAssertionError, ); }); + + testWidgets('input imm channel calls are ordered correctly', (WidgetTester tester) async { + final List log = []; + SystemChannels.textInput.setMockMethodCallHandler((MethodCall methodCall) async { + log.add(methodCall); + }); + const String testText = 'flutter is the best!'; + final TextEditingController controller = TextEditingController(text: testText); + final EditableText et = EditableText( + showSelectionHandles: true, + maxLines: 2, + controller: controller, + focusNode: FocusNode(), + cursorColor: Colors.red, + backgroundCursorColor: Colors.blue, + style: Typography(platform: TargetPlatform.android).black.subhead.copyWith(fontFamily: 'Roboto'), + keyboardType: TextInputType.text, + ); + + await tester.pumpWidget(MaterialApp( + home: Align( + alignment: Alignment.topLeft, + child: SizedBox( + width: 100, + child: et, + ), + ), + )); + + await tester.showKeyboard(find.byType(EditableText)); + expect(log.length, 7); + // TextInput.show should be before TextInput.setEditingState + final List logOrder = ['TextInput.setClient', 'TextInput.show', 'TextInput.setEditableSizeAndTransform', 'TextInput.setStyle', 'TextInput.setEditingState', 'TextInput.setEditingState', 'TextInput.show']; + int index = 0; + for (MethodCall m in log) { + expect(m.method, logOrder[index]); + index++; + } + }); } class MockTextSelectionControls extends Mock implements TextSelectionControls {