带有 iOS 应用程序钥匙串的 Flutter 自动填充希望在 API 请求完成后显示保存或更新密码提示,而不是在文本字段提交或按钮点击时显示。
我有一个带有登录页面的 Flutter 应用程序。
登录页面包含电子邮件地址和密码的文本字段,以及登录 API 调用。凭据是从钥匙串中填充的。但是,当用户从钥匙串中选择凭据并编辑密码字段时,API 请求已启动。出现更新密码提示;但是,我想仅在 API 请求完成时显示“保存密码”或“更新密码”提示。
请使用以下代码。
Scaffold(
appBar: AppBar(
title: Text("Password Autofill"),
backgroundColor: Colors.deepPurpleAccent,
),
body: Container(
padding: EdgeInsets.all(30),
child: AutofillGroup(
child:Column(
children: [
TextField(
autofillHints: [AutofillHints.username],
decoration: InputDecoration(
hintText: "Username"
),
),
TextField(
obscureText: true,
autofillHints: [AutofillHints.password],
decoration: InputDecoration(
hintText: "Password"
),
),
ElevatedButton(
onPressed: (){
//--- trigger Password Save
TextInput.finishAutofillContext();
//--- OR Your Navigation----
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context){
return Panel();
}));
},
child:Text("Log In")
)
],
)
),
),
)
我希望它会有所帮助。 答案参考