如何使文本字段在输入数字的某些位置有连字符 [英] How can i make textfield with hyphen at certain places of input number in flutter
本文介绍了如何使文本字段在输入数字的某些位置有连字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一个UI,我必须在其中显示输入文本字段,如下所示:
我试着这样做,但做不到,因为我是新的扑翼。有没有哪种小工具可以满足这个要求,或者你可以指导我如何制作这个小工具。
推荐答案
使用此包flutter_masked_text,您可以如下所示。这将在用户键入数字时在所需位置使用连字符自动设置文本格式。
class _MyWidgetState extends State<MyWidget> {
MaskedTextController tc = MaskedTextController(mask: '00000-0000000-0');
@override
Widget build(BuildContext context) {
return TextField(
controller: tc,
decoration: InputDecoration(
hintText: 'e.g. 61101-1234524-1',
),
);
}
}
这篇关于如何使文本字段在输入数字的某些位置有连字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文