Flutter 自动填充登录

问题描述 投票:0回答:3

我发现了几个与此类似的问题,但没有任何效果。 我可能没有掌握自动填充功能的基础知识。

我正在 iPhone 11 Pro(物理设备)上测试我的代码。我希望它也能在 Android 上运行,但我目前没有任何物理设备可以测试,只有模拟器。

我有一个简单的登录表单,其中包含电子邮件和密码字段:

TextFormField(keyboardType: TextInputType.emailAddress,
autofillHints: [AutofillHints.email],
textInputAction: TextInputAction.next), 

TextFormField(obscureText: true,
autofillHints: [AutofillHints.password],
onEditingComplete: () => TextInput.finishAutofillContext()),

插入数据后,我将它们保存在两个变量中(

_email
_password
),当按下提交按钮时,我用
FirebaseAuth
检查它们。登录过程工作正常。

我想保存这些凭据并在下次登录时记住它们。 我将它们保存在

secure_storage
上,因为我在某处读到这会将它们保存在 iOS 钥匙串上...但没有执行任何操作。

提交表单时,系统不会要求我保存凭据。当我单击字段进行填充时,键盘建议我打开“密码”,但没有与我的应用程序相关的实例。

我读了一些帖子,但我不明白我应该做什么。看起来应该是自动工作的,但事实并非如此。

我需要检查一些设置吗? 我需要导入一些库吗?

请尽可能清楚地说明,这是我的第一个 Flutter 应用程序。 谢谢。

flutter authentication autofill
3个回答
6
投票

AutofillGroup
包裹您的 TextFormFields,以便用户使用密码管理器保存它们。

AutofillGroup(
  child: Column(
    children: <Widget>[
      TextFormField(
        keyboardType: TextInputType.emailAddress,
        autofillHints: [AutofillHints.email],
        textInputAction: TextInputAction.next,
      ),
      TextFormField(
        obscureText: true,
        autofillHints: [AutofillHints.password],
        onEditingComplete: () =>
          TextInput.finishAutofillContext(),
      ),
    ],
  ),
),

如果您希望应用程序处理自动填充,您需要从

secure_storage
获取凭据并将值插入表单中。


3
投票
 @override
  Widget build(BuildContext context) {
    return AutofillGroup(
      child: Column(
        children: <Widget>[
          TextField(controller: username, autofillHints: [AutofillHints.username]),
          TextField(controller: newPassword, autofillHints: [AutofillHints.newPassword]),

        ],
      ),
    );
  }

0
投票

适用于任何可以在 Android 上存档自动填充和提示对话框但不能在 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 中找到,以及它们在不同平台上的可用性。

© www.soinside.com 2019 - 2024. All rights reserved.