如何在不单击按钮的情况下将textformfield值添加到列表

时间:2020-10-23 08:47:43

标签: flutter

TextFormField(
                onChanged: (value){
                  currentoption = value;
                  alloptions.add(currentoption.toString());
                },
                style: TextStyle(
                  color: Colors.white,
                ),
                decoration: InputDecoration(
                  border: InputBorder.none,
                  hintText: "  Enter Option",
                  hintStyle: TextStyle(
                    color: Colors.white70,
                  ),
                ),
              ),

如果要完成输入,我会尝试将输入文本保存到列表中,但是我是否要打印alloptions列表的值,它会按字符值打印字符,如何键入单词。

1 个答案:

答案 0 :(得分:0)

这是因为每次您在文本字段中输入时都会触发onChange :,并且在您的onChange中:请使用variable.add(value.toString),这意味着您每次在文本字段中输入时都会在旧文本之后添加新文本