TextInputType.number只能弹出数字键盘,还是可以输入特殊字符等,需要加上WhitelistingTextInputFormatter.digitsOnly
TextField(
inputFormatters: [
LengthLimitingTextInputFormatter(11),
WhitelistingTextInputFormatter.digitsOnly
],
keyboardType: TextInputType.number,
WhitelistingTextInputFormatter 源码里写的很清楚
/// A [WhitelistingTextInputFormatter] that takes in digits `[0-9]` only.
static final WhitelistingTextInputFormatter digitsOnly
= WhitelistingTextInputFormatter(RegExp(r'\d+'));
images-3.png
03c753024ca6782c9cc5d35a2f25682a.png
更多详解:
喜欢可以加Q群号:913934649,点赞,关注
简书: https://www.jianshu.com/u/88db5f15770d
网友评论