Flutter TextField設置默認值默認值和光標位置


主要通過controller 實現,具體代碼如下

TextField(
          //輸入鍵盤類型 keyboardType: TextInputType.text, autofocus: true, decoration: InputDecoration( border: OutlineInputBorder( borderRadius: BorderRadius.circular(
30), borderSide: BorderSide.none), ), onChanged: (value) { this._keyword = value; }, controller: TextEditingController.fromValue(TextEditingValue( text: '${this._keyword == null ? "" : this._keyword}', //判斷keyword是否為空 // 保持光標在最后 selection: TextSelection.fromPosition(TextPosition( affinity: TextAffinity.downstream, offset: '${this._keyword}'.length)))), ),

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM