如何更改文本字段的设置值

问题描述

所以我有 TextFormField 并且它有一个设定值。但是,当我尝试通过在 Feild 中键入来更改它的值时,它只会恢复为指定的值。这是我的代码

TextFormField(
                onEditingComplete: () {

                  FocusScope.of(context).unfocus();
                  setState(() {
                    
                    // THIS IS WHERE I NEED TO CHANGE ITS VALUE

                  });

                },controller: _titleController..text = newTask.title,//newTask IS AN OBJECT
                cursorHeight: 23.0,decoration: Inputdecoration(
                  disabledBorder: UnderlineInputBorder(),border: OutlineInputBorder(),hintText: "Enter Text",labelText: "Title",labelStyle: TextStyle(
                    fontSize: 20.0
                  ),),

我需要以某种方式将 _titleController.text 设置为单击 enter 或勾选按钮时字段中的值 - 但由于显而易见的原因,我不能只执行 _titleController.text = _titleController.text;。请帮忙。如果您需要更多详细信息,请发表评论

解决方法

改成这样:

@override
  void initState() {
    super.initState();
   _titleController.text = newTask.title;
  }
.
.
.
.
.
//And in your TextFormField
controller: _titleController,
,

您将 newTask.title 的值分配给 _titleController.text

controller: _titleController..text = newTask.title,//newTask IS AN OBJECT

制作:

controller: _titleController

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...