1

所以我有 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;

4

2 回答 2

0

将其更改为:

@override
  void initState() {
    super.initState();
   _titleController.text = newTask.title;
  }
.
.
.
.
.
//And in your TextFormField
controller: _titleController,
于 2021-04-29T22:04:05.187 回答
0

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

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

做了:

controller: _titleController
于 2021-04-29T22:04:33.087 回答