我正在使用TextFormField来获取数字作为输入,因此我使用了此代码段
keyboardType: TextInputType.number,
这是我的TextFormField小部件代码
TextFormField(
keyboardType: TextInputType.number,
style: textstyle,
controller: principal,
validator: (String value) {
if (value.isEmpty) {
return "Please enter principal amount e.g 3245";
}
},
decoration: InputDecoration(
labelText: "Principal",
labelStyle: textstyle,
hintText: "Rupees",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0))),
)
但是现在我可以在此处显示的相同字段中粘贴一些文本
因此,现在我该如何格式化TextFormfield来限制仅键入数字和限制粘贴文本?
最佳答案
您可以尝试使用WhitelistingTextInputFormatter
喜欢inputFormatters: [WhitelistingTextInputFormatter.digitsOnly],
参见官方docs
关于android - Flutter:KeyboardType属性在TextFormField中无法按预期工作,仍然可以粘贴文本。如何更改输入类型?(Flutter),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58099855/