可拒绝的窗口小部件在被拒绝后始终显示错误

时间:2019-03-20 12:51:52

标签: flutter

我有一个可忽略的小部件,它会产生常见错误flutter: Another exception was thrown: A dismissed Dismissible widget is still part of the tree.。这是我的main.dart代码

return MaterialApp(
    title: "To-Do List V2",
    home: Scaffold(
        appBar: AppBar(
          title: Text("To-Do List V2"),
        ),
        body: Flex(
          direction: Axis.vertical,
          children: <Widget>[
            Flexible(
              fit: FlexFit.tight,
              child: Column(children: <Widget>[
                Container(
                  child: TextField(
                    decoration: InputDecoration(
                        hintText: "Enter title of task to be added"),
                    onChanged: (taskTextField) {
                      setState(() {
                        TaskTextField = taskTextField;
                        print(TaskTextField);
                      });
                    },
                  ),
                  margin: EdgeInsets.all(16.0),
                ),
                CheckboxListTile(
                  title: Text("Important"),
                  activeColor: Colors.blue,
                  value: TaskIsImportant,
                  onChanged: (val) {
                    setState(() {
                      TaskIsImportant = !TaskIsImportant;
                      print(TaskIsImportant);
                    });
                  },
                ),
                Text(
                  "Tip: Tap on your task to remove it",
                  style: TextStyle(fontSize: 15.0),
                ),
                Container(
                  margin: EdgeInsetsDirectional.fromSTEB(117, 10, 117, 5),
                  child: Row(
                    children: <Widget>[
                      RaisedButton(
                        child: Icon(Icons.add),
                        onPressed: () {
                          setState(() {
                            if (TaskIsImportant) {
                              taskTextList.add("❗️$TaskTextField");

                            } else {
                              taskTextList.add(TaskTextField);
                              }
                          });
                        },
                      ),
                      RaisedButton(
                        child: Icon(Icons.done_all),
                        onPressed: () {
                          setState(() {
                            taskTextList = [];
                          });
                        },
                      ),
                    ],
                  ),
                ),
                Expanded(
                  child: ListView.builder(
                    itemBuilder: (context, index) {
                      var title = taskTextList[index];
                      padding:
                      EdgeInsets.all(16.0);

                      return Dismissible(
                        key: Key(title),
                        onDismissed: (direction) => taskTextList.removeAt(index),

                        child: ListTile(
                          title: Text(
                            title,
                            style: TextStyle(fontSize: 20.0),
                          ),
                        ),
                      );
                    },
                    itemCount: taskTextList.length,
                  ),
                )
              ]),
            ),
          ],
        )));
   }
}

我尝试了其他方法,例如创建一个特殊功能,例如从其他帖子中提到的列表中删除项目,但无济于事。请告诉我这段代码有什么问题。我正在运行Flutter 1.3.10版本。预先感谢!

0 个答案:

没有答案