flutter 设置 TextField 的值
String _newContent = "";
GlobalKey _newContentKey = new GlobalKey();
......
Container(
padding: EdgeInsets.fromLTRB(0.00, 5.00, 0.00, 0.00),
child: new TextField(
key: _newContentKey,
controller: new TextEditingController(),
style: TextStyle(fontSize: 9.00, color: Colors.black),
autocorrect: false,
maxLines: 2,
decoration: new InputDecoration(
labelText: '内容',
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(3.0))),
onChanged: (val) {
if (val.length > 100) {
_newContent = val.substring(0, 100);
(_newContentKey.currentWidget as TextField)
.controller
.text = _newContent;
} else {
_newContent = val;
}
},
)..controller.text = _newContent,
),
主要需要的是 controller
浙公网安备 33010602011771号