我正在尝试使用 Google 密码管理器自动填充电子邮件和密码。这似乎适用于 Android,但不适用于 Web。
示例:
Form(
key: key,
child: AutofillGroup(
child: Column(
children: [
TextFormField(
autofillHints: const [AutofillHints.email],
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
),
TextFormField(autofillHints: const [AutofillHints.password],),
ElevatedButton(
onPressed: (){
TextInput.finishAutofillContext();
Navigator.of(context).pushReplacementNamed('/home');
},
child: const Text('Login'),
),
],
),
),
),
当我按下“登录”按钮时,浏览器(Google Chrome)会显示一个弹出窗口,允许我使用密码管理器保存电子邮件和密码,然后转到主屏幕。
问题是当我尝试再次登录时:电子邮件和密码已保存,但它们不会自动填充,或者当我单击任何字段时甚至不会显示为建议。
注意:我已经链接了google账户并开启了同步。
在文本字段中使用
AutofillGroup
和 autofillHints
有效。您可以通过flutter Campus在这里找到代码。
AutofillGroup(
child:Column(
children: [
TextField(
autofillHints: [AutofillHints.username],
decoration: InputDecoration(
hintText: "Username"
),
),
TextField(
obscureText: true,
autofillHints: [AutofillHints.password],
decoration: InputDecoration(
hintText: "Password"
),
),
],
)
)