From f268f82035bf40f6bc11901aa80e83df8e76cf96 Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Tue, 4 Jan 2022 15:20:09 -0800 Subject: [PATCH] Fix autofill eligibility check (#95210) --- .../lib/src/widgets/editable_text.dart | 2 +- .../test/widgets/editable_text_test.dart | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index f7518ca6b98..67f5674426e 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -2191,7 +2191,7 @@ class EditableTextState extends State with AutomaticKeepAliveClien bool get _hasInputConnection => _textInputConnection?.attached ?? false; /// Whether to send the autofill information to the autofill service. True by /// default. - bool get _needsAutofill => widget.autofillHints?.isNotEmpty ?? true; + bool get _needsAutofill => _effectiveAutofillClient.textInputConfiguration.autofillConfiguration.enabled; void _openInputConnection() { if (!_shouldCreateInputConnection) { diff --git a/packages/flutter/test/widgets/editable_text_test.dart b/packages/flutter/test/widgets/editable_text_test.dart index 10c31a27ee4..1f1561ac5cb 100644 --- a/packages/flutter/test/widgets/editable_text_test.dart +++ b/packages/flutter/test/widgets/editable_text_test.dart @@ -6585,6 +6585,7 @@ void main() { 'TextInput.setStyle', 'TextInput.setEditingState', 'TextInput.show', + 'TextInput.requestAutofill', 'TextInput.setEditingState', 'TextInput.show', 'TextInput.setCaretRect', @@ -6648,6 +6649,7 @@ void main() { 'TextInput.setStyle', 'TextInput.setEditingState', 'TextInput.show', + 'TextInput.requestAutofill', 'TextInput.setCaretRect', ]; expect( @@ -6690,6 +6692,7 @@ void main() { 'TextInput.setStyle', 'TextInput.setEditingState', 'TextInput.show', + 'TextInput.requestAutofill', 'TextInput.setEditingState', 'TextInput.show', 'TextInput.setCaretRect', @@ -6740,6 +6743,7 @@ void main() { 'TextInput.setStyle', 'TextInput.setEditingState', 'TextInput.show', + 'TextInput.requestAutofill', 'TextInput.setEditingState', 'TextInput.show', 'TextInput.setCaretRect', @@ -8974,6 +8978,53 @@ void main() { await tester.pump(); expect(scrollController.offset.roundToDouble(), 0.0); }); + + testWidgets('Autofill enabled by default', (WidgetTester tester) async { + final FocusNode focusNode = FocusNode(); + await tester.pumpWidget( + MaterialApp( + home: EditableText( + autofocus: true, + controller: TextEditingController(text: 'A'), + focusNode: focusNode, + style: textStyle, + cursorColor: Colors.blue, + backgroundCursorColor: Colors.grey, + cursorOpacityAnimates: true, + ), + ), + ); + + assert(focusNode.hasFocus); + expect( + tester.testTextInput.log, + contains(matchesMethodCall('TextInput.requestAutofill')), + ); + }); + + testWidgets('Autofill can be disabled', (WidgetTester tester) async { + final FocusNode focusNode = FocusNode(); + await tester.pumpWidget( + MaterialApp( + home: EditableText( + autofocus: true, + controller: TextEditingController(text: 'A'), + focusNode: focusNode, + style: textStyle, + cursorColor: Colors.blue, + backgroundCursorColor: Colors.grey, + cursorOpacityAnimates: true, + autofillHints: null, + ), + ), + ); + + assert(focusNode.hasFocus); + expect( + tester.testTextInput.log, + isNot(contains(matchesMethodCall('TextInput.requestAutofill'))), + ); + }); } class UnsettableController extends TextEditingController {