我基本上有一个登录页面,用户可以在其中创建帐户,还有一个登录页面。
我想像很多应用程序一样将用户电子邮件和密码保存在钥匙串中,但我仍然无法收到此提示:
使用此 Flutter 代码:(复制/粘贴/运行)
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: AutoFillPage(),
);
}
}
class AutoFillPage extends StatefulWidget {
const AutoFillPage({Key? key}) : super(key: key);
@override
_AutoFillPageState createState() => _AutoFillPageState();
}
class _AutoFillPageState extends State<AutoFillPage> {
var isSameAddress = true;
final billingAddress1Key = UniqueKey();
final billingAddress2Key = UniqueKey();
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text(
"Auto Fill"
),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Form(
key: _formKey,
child: AutofillGroup(
onDisposeAction: AutofillContextAction.commit,
child: ListView(
padding: EdgeInsets.symmetric(horizontal: 16),
children: [
Column(
children: [
TextFormField(
autofillHints: [AutofillHints.email],
validator: (value) =>
value!.isEmpty ? "some email please" : null,
decoration: const InputDecoration(
labelText: 'email',
hintText: 'enter email adress',
),
),
TextFormField(
autofillHints: [AutofillHints.password],
validator: (value) =>
value!.isEmpty ? "some password please" : null,
decoration: const InputDecoration(
labelText: 'password',
hintText: 'enter your password',
),
),
],
),
MaterialButton(
child: Text("submit"),
onPressed: () {
if (_formKey.currentState!.validate()) {
TextInput.finishAutofillContext(shouldSave: true);
debugPrint("----> Naigate to 2nd Page");
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
}
},
),
],
),
),
),
),
);
@override
void dispose() {
debugPrint("Form widget disposed");
super.dispose();
}
}
class SecondRoute extends StatefulWidget {
@override
_SecondRouteState createState() => _SecondRouteState();
}
class _SecondRouteState extends State<SecondRoute> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Second Route"),
),
body: Center(
child: ElevatedButton(
onPressed: () {
debugPrint("----> Naigate back to first page");
Navigator.pop(context);
//Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => MyApp()));
},
child: Text('Go back!'),
),
),
);
}
@override
void dispose() {
debugPrint("2nd Screen widget disposed");
super.dispose();
}
}
我在真机iPhone 12 Pro Max上启用了密码保存和自动填充功能。
我还想让它在登录页面的另一侧工作:当点击第一个填充时,我希望获得自动填充提示(如 Netflix、亚马逊...)以快速登录。
这里的基本代码适用于 Android,但不适用于 iOS。 iOS 是否需要额外的配置而我可能会错过?
感谢您的帮助/领导
您需要为 iOS 设置关联域:https://developer.apple.com/documentation/xcode/supporting-linked-domains
医生:
https://api.flutter.dev/flutter/material/TextField/autofillHints.html
设置 iOS 自动填充: 为了提供最佳的用户体验并确保您的应用完全支持 iOS 上的密码自动填充,请按照以下步骤操作:
- 设置您的 iOS 应用程序的关联域。
- 某些自动填充提示仅适用于特定的键盘类型。例如,AutofillHints.name 需要 TextInputType.name,而 AutofillHints.email 仅适用于 TextInputType.emailAddress。确保输入字段具有兼容的键盘类型。根据经验,TextInputType.name 与 iOS 上预定义的许多自动填充提示配合得很好。
我调用了 TextInput.finishAutofillContext 但自动填充保存 没有显示提示
iOS:iOS 在保存用户密码时可能不会显示提示或任何其他视觉指示。进入“设置”->“密码”并检查您的新密码是否已保存。如果没有在应用程序中正确设置关联域,则保存密码或自动生成强密码都不起作用。要设置关联域,请按照developer.apple.com/documentation/safariservices/supporting_linked_domains_in_your_app 中的说明进行操作。为了获得最佳结果,平台的自动填充服务需要理解提示字符串。提示字符串的常用值可以在 AutofillHints 中找到,以及它们在不同平台上的可用性。