gpt4 book ai didi

authentication - Flutter 中的 minLength 文本字段属性

转载 作者:行者123 更新时间:2023-12-05 07:10:20 26 4
gpt4 key购买 nike

我正在尝试创建一个密码文本字段,我希望用户输入至少 8 个字符。当设置了最大长度时,我真的很喜欢文本字段上可见的最大长度字符计数器的工作方式,我想知道是否有任何等效的最小长度。谢谢!

最佳答案

你必须使用 TextFormField而不是 TextField .

检查 this SO post :

For Text Field Validation use TextFormField instead of TextField.TextFormField needs to be wrapped with Form widget (If there aretwo ore more textformfields you can wrap their parent widget with formwidget).Form widget requires key and autovalidate boolean (it'soptional but it's recommended to show message to user when theyhaven't validated and as soon as they validate message stops showing).We create two variables and assign it to Form.Then we need avalidator in which we validate according to our requirements.(If you need to add more validations you can add multiple ifconditions.).Finally on field submitted we check if user has validatedthe form if validated we perform our desired action else we setautovalidate variable to true to perform autovalidation.

例如

TextFormField(
...
validator: (String value) {
return value.length < 8 ? 'Minimum character length is 8' : null;
}
)

关于authentication - Flutter 中的 minLength 文本字段属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61254951/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com