颤振更新文字 [英] Flutter update countertext
本文介绍了颤振更新文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Flutter中,当用户在 TextFormField
中键入内容时, inputDecoration的
计数器文本属性不会更改.在用户键入文字时,可以减少原语吗?
In Flutter, inputDecoration's
countertext property does not change as the user is typing in the TextFormField
. Is it possible to decrement the countertext as the user is typing?
TextFormField(
keyboardType: TextInputType.number,
decoration: new InputDecoration(
counterText: "9",
hintText: "Enter exact order number",
),
)
推荐答案
我对此 answer 处理您的问题
class StackEditText extends StatefulWidget {
@override
_StackEditTextState createState() => _StackEditTextState();
}
class _StackEditTextState extends State<StackEditText> {
TextEditingController _controller = new TextEditingController();
void onValueChange() {
setState(() {
_controller.text;
});
}
@override
void initState() {
super.initState();
_controller.addListener(onValueChange);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Container(
child: TextFormField(
controller: _controller,
maxLength: 9,
decoration: InputDecoration(
counterText: "${9 - _controller.text.length}",
hintText: 'Enter exact order number',
),
),
),
);
}
}
这篇关于颤振更新文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文