简体   繁体   English

Flutter 中不推荐使用 TextFormField 的自动验证

[英]Autovalidate of TextFormField is deprecated in Flutter

'autovalidate' is deprecated and shouldn't be used. 'autovalidate' 已弃用,不应使用。 Use autoValidateMode parameter which provide more specific behaviour related to auto validation.使用 autoValidateMode 参数,该参数提供与自动验证相关的更具体的行为。 This feature was deprecated after v1.19.0.. Try replacing the use of the deprecated member with the replacement.此功能在 v1.19.0 之后已弃用。。尝试将已弃用成员的使用替换为替换。 enter image description here在此处输入图像描述

autovalidate is replaced by autovalidateMode autovalidate 被 autovalidateMode 取代

Auto validation is deprecated and replaced by an enum.自动验证已弃用并由枚举代替。 So you should migrate to the new version.所以你应该迁移到新版本。

All you need to do is replace autovalidate: true with autovalidateMode: AutovalidateMode.always您需要做的就是将autovalidate: true替换为autovalidateMode: AutovalidateMode.always

The different supported modes are支持的不同模式是

  1. AutovalidateMode.always AutovalidateMode.always
  2. AutovalidateMode.disabled AutovalidateMode.disabled
  3. AutovalidateMode.onUserInteraction AutovalidateMode.onUserInteraction

Example:例子:

Code before migration:迁移前的代码:

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FormField(
      autovalidate: true,
      builder: (FormFieldState state) {
        return Container();
      },
    );
  }
}

Code after migration:迁移后的代码:

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FormField(
      autovalidateMode: AutovalidateMode.always,
      builder: (FormFieldState state) {
        return Container();
      },
    );
  }
}

autovalidate is deprecated from Flutter v1.19自动验证已从 Flutter v1.19 弃用

Replace autovalidate with autovalidateMode .autovalidate替换为autovalidateMode

autovalidateMode can have one of the below 3 values: autovalidateMode可以具有以下 3 个值之一:

  1. autovalidateMode: AutovalidateMode.disabled : No auto validation will occur. autovalidateMode: AutovalidateMode.disabled :不会发生自动验证。

  2. autovalidateMode: AutovalidateMode.always : Used to auto-validate FormField even without user interaction. autovalidateMode: AutovalidateMode.always : 即使没有用户交互,也用于自动验证 FormField。

  3. autovalidateMode: AutovalidateMode.onUserInteraction : Used to auto-validate FormField only after each user interaction. autovalidateMode: AutovalidateMode.onUserInteraction : 用于仅在每次用户交互后自动验证 FormField。

I suggest try all the above values one by one and use the one that fulfills ur requirement.我建议一一尝试上述所有值,并使用满足您要求的值。

autovalidate 已被贬值,现在您需要使用 autovalidateMode: AutovalidateMode.always 通过以下方式检查颤振文档: https ://docs.flutter.dev/release/break-changes/form-field-autovalidation-api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter Textformfield 验证器将最后一个 TextFormfield 集中在验证错误上,而不是第一个 - Flutter Textformfield validator Focuses Last TextFormfield on validation error instead of first 如何更改 TextFormField() 小部件颜色 Flutter - How to change TextFormField() widget color Flutter Flutter:向 Column 添加了一个额外的 TextFormField 但显示没有变化 - Flutter: Added an additional TextFormField to Column but no change in display Flutter-在TextTextField上显示对话框编号选择器 - Flutter - Show Dialog NumberPicker on Tap TextFormField 表单的 TextFormField 中的多个光标抖动 - Multiple cursor in form's TextFormField flutter 如何在 Flutter 中对齐 TextFormField 旁边的文本? - How to align Text next to TextFormField in Flutter? 仅当专注于颤动时如何在 TextFormField() 上显示计数器文本? - How to display counter text on TextFormField() only when focused in flutter? 在 Flutter 中,如何更改 TextFormField 验证错误行样式? - In Flutter, How can I change TextFormField validation error line style? 在 listview flutter 内的 textformfield 中按下数字后键盘关闭 - keyboard close after pressing a number in textformfield inside listview flutter 在Flutter TextFormField中输入数据时,键盘不断消失 - Keyboard keeps disappearing while entering data in Flutter TextFormField
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM