我正在尝试使用文本字段创建一种论坛。事实是,当您填写黑色并按下一步,然后再次返回时,文本字段将显示为空,好像其中没有任何值,但实际上已保存。我想要它,这样即使前进后退,您也可以看到自己输入的内容。我将附上一些照片,以便您可以更好地理解我的意思。
这是文本字段的照片:https : //gyazo.com/9ceb0ef4f27db1be842cbdfac885fc01
在这张照片中,我填补了空白:https : //gyazo.com/6365ab3fcc9d8167a1c9163563fbf3d7
比我前进:https : //gyazo.com/8490115e74b57e96cd1f3a9486db5fad
当我再次返回时,文本字段看起来为空,但值不为空,我想要它,以便仍可以看到其中的值:https : //gyazo.com/07eec4c58149641926d7f037bb0f949c
在这里,我将放置TextFIeld的代码:
Container(
margin: EdgeInsets.only(top: 20),
width: 360,
child:
Form(
autovalidateMode: AutovalidateMode.always,
onChanged: () {
Form.of(primaryFocus.context).save();
},
child: TextFormField(
decoration: new InputDecoration(
labelText: "Event Name",
fillColor: Colors.white,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(),
),
//fillColor: Colors.green
),
validator: (val) {
if (val.length == 0) {
return "Event Name cannot be empty";
} else {
return null;
}
},
onSaved: (String value) {
eventname = value;
},
style: new TextStyle(
fontFamily: "Poppins",
))))
通过加载保存的值将初始值添加到textformfield中
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句