[英]A dismissed Dismissible widget is still part of the tree. In flutter
I have an application which uses firebase as my database and I have this problem on the screen我有一个使用 firebase 作为我的数据库的应用程序,我在屏幕上遇到了这个问题
I'm adding Dismissible widget to delete the items.我正在添加 Dismissible 小部件以删除项目。 It works properly on the database when I look but not on the app itself.当我查看但不适用于应用程序本身时,它可以在数据库上正常工作。
Here is my dismissible:这是我的解雇:
return Dismissible(
key: Key(todos[index].title),
background: Container(padding:EdgeInsets.only(left: 20),alignment: Alignment.centerLeft,
child:Icon(Icons.delete),
color:Colors.red,
),
onDismissed: (direction) async{
await DatabaseService().removeTodo(todos[index].uid);
},
child: ListTile(
onTap: (){
DatabaseService().completTask(todos[index].uid);
},
leading: Container(
padding: EdgeInsets.all(2),
height: 30,
width: 30,
decoration: BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle
),
child: todos[index].isComplet? Icon(Icons.check,color: Colors.white):Container(
),
),
title: Text(
todos[index].title,
)
),
and here is my database services:这是我的数据库服务:
class DatabaseService{
CollectionReference todosCollection = FirebaseFirestore.instance.collection("Todos");
Future createNewTodo(String title) async{
return await todosCollection.add({
"title":title,
"isComplet":false,
});
}
Future completTask(uid)async{
await todosCollection.doc(uid).update({"isComplet":true});
}
Future removeTodo(uid) async{
await todosCollection.doc(uid).delete();
}
List<Todo> todoFromFirestore(QuerySnapshot snapshot){
return snapshot.docs.map((e) {
return Todo(uid: e.id,
title: (e["title"]),
isComplet: e["isComplet"],);
}).toList();
}
Stream<List<Todo>> listTodos() {
return todosCollection.snapshots().map(todoFromFirestore);
}
}
If someone can help me I will be really grateful I don't know why this error occurs.如果有人可以帮助我,我将不胜感激,我不知道为什么会发生此错误。
Okay so after some research I fix my problem by myself, the problem is definitely the index so I change:好的,所以经过一些研究,我自己解决了我的问题,问题肯定是索引,所以我改变了:
key: Key(todos[index].title),
for:为了:
key: UniqueKey(),
And It's work correctly, the problem come from the removed item on the list, the widget cannot recognize it.它工作正常,问题来自列表中已删除的项目,小部件无法识别它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.