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