Skip to content

Commit f268f82

Browse files
Fix autofill eligibility check (#95210)
1 parent 5b6de03 commit f268f82

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

packages/flutter/lib/src/widgets/editable_text.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
21912191
bool get _hasInputConnection => _textInputConnection?.attached ?? false;
21922192
/// Whether to send the autofill information to the autofill service. True by
21932193
/// default.
2194-
bool get _needsAutofill => widget.autofillHints?.isNotEmpty ?? true;
2194+
bool get _needsAutofill => _effectiveAutofillClient.textInputConfiguration.autofillConfiguration.enabled;
21952195

21962196
void _openInputConnection() {
21972197
if (!_shouldCreateInputConnection) {

packages/flutter/test/widgets/editable_text_test.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6585,6 +6585,7 @@ void main() {
65856585
'TextInput.setStyle',
65866586
'TextInput.setEditingState',
65876587
'TextInput.show',
6588+
'TextInput.requestAutofill',
65886589
'TextInput.setEditingState',
65896590
'TextInput.show',
65906591
'TextInput.setCaretRect',
@@ -6648,6 +6649,7 @@ void main() {
66486649
'TextInput.setStyle',
66496650
'TextInput.setEditingState',
66506651
'TextInput.show',
6652+
'TextInput.requestAutofill',
66516653
'TextInput.setCaretRect',
66526654
];
66536655
expect(
@@ -6690,6 +6692,7 @@ void main() {
66906692
'TextInput.setStyle',
66916693
'TextInput.setEditingState',
66926694
'TextInput.show',
6695+
'TextInput.requestAutofill',
66936696
'TextInput.setEditingState',
66946697
'TextInput.show',
66956698
'TextInput.setCaretRect',
@@ -6740,6 +6743,7 @@ void main() {
67406743
'TextInput.setStyle',
67416744
'TextInput.setEditingState',
67426745
'TextInput.show',
6746+
'TextInput.requestAutofill',
67436747
'TextInput.setEditingState',
67446748
'TextInput.show',
67456749
'TextInput.setCaretRect',
@@ -8974,6 +8978,53 @@ void main() {
89748978
await tester.pump();
89758979
expect(scrollController.offset.roundToDouble(), 0.0);
89768980
});
8981+
8982+
testWidgets('Autofill enabled by default', (WidgetTester tester) async {
8983+
final FocusNode focusNode = FocusNode();
8984+
await tester.pumpWidget(
8985+
MaterialApp(
8986+
home: EditableText(
8987+
autofocus: true,
8988+
controller: TextEditingController(text: 'A'),
8989+
focusNode: focusNode,
8990+
style: textStyle,
8991+
cursorColor: Colors.blue,
8992+
backgroundCursorColor: Colors.grey,
8993+
cursorOpacityAnimates: true,
8994+
),
8995+
),
8996+
);
8997+
8998+
assert(focusNode.hasFocus);
8999+
expect(
9000+
tester.testTextInput.log,
9001+
contains(matchesMethodCall('TextInput.requestAutofill')),
9002+
);
9003+
});
9004+
9005+
testWidgets('Autofill can be disabled', (WidgetTester tester) async {
9006+
final FocusNode focusNode = FocusNode();
9007+
await tester.pumpWidget(
9008+
MaterialApp(
9009+
home: EditableText(
9010+
autofocus: true,
9011+
controller: TextEditingController(text: 'A'),
9012+
focusNode: focusNode,
9013+
style: textStyle,
9014+
cursorColor: Colors.blue,
9015+
backgroundCursorColor: Colors.grey,
9016+
cursorOpacityAnimates: true,
9017+
autofillHints: null,
9018+
),
9019+
),
9020+
);
9021+
9022+
assert(focusNode.hasFocus);
9023+
expect(
9024+
tester.testTextInput.log,
9025+
isNot(contains(matchesMethodCall('TextInput.requestAutofill'))),
9026+
);
9027+
});
89779028
}
89789029

89799030
class UnsettableController extends TextEditingController {

0 commit comments

Comments
 (0)