Fix autofill eligibility check (#95210)

This commit is contained in:
LongCatIsLooong 2022-01-04 15:20:09 -08:00 committed by GitHub
parent 5b6de035ce
commit f268f82035
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 1 deletions

View File

@ -2191,7 +2191,7 @@ class EditableTextState extends State<EditableText> 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) {

View File

@ -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 {