Flutter TextFormField 如何设置初始值的问题


class _FooState extends State<Foo> {
  TextEditingController _controller;
 
  @override
  void initState() {
    super.initState();
//setState很重要不然数据不会更新!!!
    setState((){
      _controller = new TextEditingController(text: '初始值');
     }
);  
} @override Widget build(BuildContext context) { return new Column( children: <Widget>[ new TextField( //设置controller, controller: _controller, ), new RaisedButton( onPressed: () { //清除输入 _controller.clear(); }, child: new Text('清除'), ), ], ); } }

注意在初始化的时候,setState一定要调用,不然数据不会正常更新!


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM