【问题标题】:Flutter save text in textfielfFlutter 在文本字段中保存文本
【发布时间】:2020-12-30 12:45:57
【问题描述】:

我正在尝试使用文本字段创建一种论坛。问题是,当您填写黑色并按下一步然后再次返回时,文本字段将显示为空,就好像您没有任何值但实际上已保存一样。我想要它,这样即使你前进和后退,你也能看到你输入的内容。我会附上一些照片,以便您更好地理解我的意思。

这是文本字段的照片: 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",
              ))))

【问题讨论】:

  • 通过加载保存的值向您的文本表单字段添加初始值
  • 非常感谢!您可以将其作为答案,我可以将其设置正确:)

标签: flutter


【解决方案1】:

通过加载保存的值向您的文本表单字段添加初始值

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-24
    • 2020-05-20
    • 2018-02-18
    • 1970-01-01
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多