diff --git a/packages/flutter/test/widgets/editable_text_test.dart b/packages/flutter/test/widgets/editable_text_test.dart index 01f8942729..9276eede19 100644 --- a/packages/flutter/test/widgets/editable_text_test.dart +++ b/packages/flutter/test/widgets/editable_text_test.dart @@ -5076,6 +5076,89 @@ void main() { ))); }); + testWidgets('Repeatedly receiving [TextEditingValue] will not trigger a keyboard request', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/66036 + final List log = []; + SystemChannels.textInput.setMockMethodCallHandler((MethodCall methodCall) async { + log.add(methodCall); + }); + final TextEditingController controller = TextEditingController(); + + final FocusNode focusNode = FocusNode(debugLabel: 'EditableText Focus Node'); + Widget builder() { + return StatefulBuilder( + builder: (BuildContext context, StateSetter setter) { + return MaterialApp( + home: MediaQuery( + data: const MediaQueryData(devicePixelRatio: 1.0), + child: Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: Material( + child: EditableText( + controller: controller, + focusNode: focusNode, + style: textStyle, + cursorColor: Colors.red, + backgroundCursorColor: Colors.red, + keyboardType: TextInputType.multiline, + onChanged: (String value) { }, + ), + ), + ), + ), + ), + ); + }, + ); + } + + await tester.pumpWidget(builder()); + await tester.tap(find.byType(EditableText)); + await tester.pump(); + + // The keyboard is shown after tap the EditableText. + expect(focusNode.hasFocus, true); + + log.clear(); + + final EditableTextState state = tester.firstState(find.byType(EditableText)); + + state.updateEditingValue(const TextEditingValue( + text: 'a', + )); + await tester.pump(); + + // Nothing called when only the remote changes. + expect(log.length, 0); + + // Hide the keyboard. + focusNode.unfocus(); + await tester.pump(); + + expect(log.length, 2); + MethodCall methodCall = log[0]; + // Close the InputConnection. + expect(methodCall, isMethodCall('TextInput.clearClient', arguments: null),); + methodCall = log[1]; + expect(methodCall, isMethodCall('TextInput.hide', arguments: null),); + // The keyboard loses focus. + expect(focusNode.hasFocus, false); + + log.clear(); + + // Send repeat value from the engine. + state.updateEditingValue(const TextEditingValue( + text: 'a', + )); + await tester.pump(); + + // Nothing called when only the remote changes. + expect(log.length, 0); + // The keyboard is not be requested after a repeat value from the engine. + expect(focusNode.hasFocus, false); + }); + testWidgets('autofocus:true on first frame does not throw', (WidgetTester tester) async { final TextEditingController controller = TextEditingController(text: testText); controller.selection = const TextSelection(