【发布时间】:2021-01-06 17:14:54
【问题描述】:
对于任何类型的提示,我都无法让 Flutter 中的自动填充正常工作。我复制了 Flutter 的示例代码,稍作修改。
bool isSameAddress = true;
final TextEditingController email = TextEditingController();
final TextEditingController billingAddress1 = TextEditingController();
final TextEditingController billingAddress2 = TextEditingController();
final TextEditingController creditCardNumber = TextEditingController();
final TextEditingController creditCardSecurityCode = TextEditingController();
final TextEditingController phoneNumber = TextEditingController();
@override
Widget build(BuildContext context) {
return ListView(
children: <Widget>[
const Text('Email'),
AutofillGroup(
child: Column(
children: <Widget>[
TextField(
controller: email,
autofillHints: <String>[AutofillHints.email],
),
],
),
),
const Text('Billing address'),
Checkbox(
value: isSameAddress,
onChanged: (bool newValue) {
setState(() { isSameAddress = newValue; });
},
),
// Again the address fields are grouped together for the same reason.
if (!isSameAddress) AutofillGroup(
child: Column(
children: <Widget>[
TextField(
controller: billingAddress1,
autofillHints: <String>[AutofillHints.streetAddressLine1],
),
TextField(
controller: billingAddress2,
autofillHints: <String>[AutofillHints.streetAddressLine2],
),
],
),
),
const Text('Credit Card Information'),
// The credit card number and the security code are grouped together as
// some platforms are capable of autofilling both fields.
AutofillGroup(
child: Column(
children: <Widget>[
TextField(
controller: creditCardNumber,
autofillHints: <String>[AutofillHints.creditCardNumber],
),
TextField(
controller: creditCardSecurityCode,
autofillHints: <String>[AutofillHints.creditCardSecurityCode],
),
],
),
),
const Text('Contact Phone Number'),
// The phone number field can still be autofilled despite lacking an
// `AutofillScope`.
TextField(
controller: phoneNumber,
autofillHints: <String>[AutofillHints.telephoneNumber],
),
],
);
}
但是对于任何类型的提示都没有显示自动填充下拉菜单。我已经在设备上开启了自动填充服务(使用 Google 的自动填充服务)并且自动填充本身可以与其他应用一起使用。
代码有什么问题?是否缺少任何导致自动填充功能被禁用的内容?
注意:我使用 Flutter 1.20.4 和 Android 10
【问题讨论】:
-
我已经尝试过自动填充并解决了与您相同的问题。同样使用 Flutter 1.20.4
-
我选择了 flutter_typeahead: ^3.0.0-nullsafety.0 包。
标签: flutter