概述

#

`TextInputClient` 接口新增了 getter `TextInputClient.currentAutofillScope`;所有 `TextInputClient` 子类都必须提供 `currentAutofillScope` 的具体实现。

这个 getter 允许 `TextInputClient` 触发涉及多个逻辑关联输入字段的自动填充。例如,一个“用户名”字段可以触发自动填充,同时填充它自己和与之关联的“密码”字段。

背景

#

在许多平台上,自动填充服务能够在一次自动填充尝试中填充多个输入字段。例如,用户名和密码字段通常可以一次性自动填充。因此,即将触发自动填充的 Flutter 输入字段也应向平台提供与其逻辑关联的其他可自动填充输入字段的信息。`TextInputClient.currentAutofillScope` 定义了与此 `TextInputClient` 逻辑关联并可以一起自动填充的输入字段组。

变更说明

#

`TextInputClient` 现在有一个额外的 getter,它返回此客户端所属的 `AutofillScope`。输入客户端使用此 getter 从同一作用域内其他可自动填充的输入字段中收集与自动填充相关的信息。

dart
abstract class TextInputClient {
  AutofillScope get currentAutofillScope;
}

如果您在编译 Flutter 应用时看到错误消息“缺少 'getter TextInputClient.currentAutofillScope' 的具体实现”,请遵循下面列出的迁移步骤。

迁移指南

#

如果您不打算为您的 `TextInputClient` 子类添加多字段自动填充支持,只需在 getter 中返回 `null`

dart
class CustomTextField implements TextInputClient {
  // Not having an AutofillScope does not prevent the input field
  // from being autofilled. However, only this input field is
  // autofilled when autofill is triggered on it.
  AutofillScope get currentAutofillScope => null;
}

如果需要多字段自动填充支持,常用的 `AutofillScope` 是 `AutofillGroup` 组件。要获取文本输入最近的 `AutofillGroup` 组件,请使用 `AutofillGroup.of(context)`

dart
class CustomTextFieldState extends State<CustomTextField> implements TextInputClient {
  AutofillScope get currentAutofillScope => AutofillGroup.of(context);
}

欲了解更多信息,请查看 `AutofillGroup`

时间线

#

发布版本:1.18.0
稳定版本中:1.20

参考资料

#

API 文档

相关议题

相关 PR