仅允许小写且无空格输入文本字段颤动 [英] Allow Only lowercase with no space Input Textfield Flutter

查看:22
本文介绍了仅允许小写且无空格输入文本字段颤动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在制作一个聊天应用程序,我希望用户提交的用户名不应该是大写的并且有空间,我可以接受该名称并稍后在onChanged功能中更改它,但我也希望用户知道它

推荐答案

Ffltter的TextFieldTextFormField具有名为inputFormatters的属性,该属性采用TextInputFormatter的列表。

适用于您的案例的TextInputFormatters示例。

FilteringTextInputFormatter.allow(RegExp("[a-z]"))

TextField(
 inputFormatters: <TextInputFormatter>[
  FilteringTextInputFormatter.allow(RegExp("[a-z]")),
 ],
)

您可以在这里看到TextInputFormatters接口文档:Reference


(颤动1.20之前):

WhitelistingTextInputFormatter(RegExp("[a-z]")),

TextField(
 inputFormatters: <TextInputFormatter>[
  WhitelistingTextInputFormatter(RegExp("[a-z]")),
 ],
)

不清楚可以参考:Reference 2Reference 3

另请查看此SOF问题:Reference 4

这篇关于仅允许小写且无空格输入文本字段颤动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆