gpt4 book ai didi

flutter - 如何修复 flutter 中的 "A dismissed Dismissible widget is still part of the tree."错误

转载 作者:IT王子 更新时间:2023-10-29 06:42:49 32 4
gpt4 key购买 nike

我正在构建一个带有可关闭小部件、firebase 和 StreamBuilder 的 flutter 应用程序,并收到以下错误“已关闭的可关闭小部件仍然是树的一部分。”

请找到以下相同的代码。

Expanded(
child: StreamBuilder(
stream: Firestore.instance
.document('/users/User1/Trips/${widget.tripId}')
.collection('TropDocs')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return const Text("Loading....");
return ListView.builder(
itemExtent: 150.0,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {

final item = snapshot.data.documents[index];
final itemID =
snapshot.data.documents[index].documentID;
final list = snapshot.data.documents;
return Dismissible(
key: Key(itemID),
// We also need to provide a function that tells our app
// what to do after an item has been swiped away.
onDismissed: (direction) {
// Remove the item from our data source.

//fBtDoc.deleteTraveldoc(item);
//Firestore.instance.collection('/users/User1/Trips/${widget.tripId}/TropDocs/').document('$itemID').delete();
setState(() {
list.removeAt(index);
});

// Then show a snackbar!
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text("$item dismissed")));
},
// Show a red background as the item is swiped away
background: Container(color: Colors.red),
child: _buildlistitem(
context, snapshot.data.documents[index])
);

}
);
},
),
)

最佳答案

可能,我迟到了,但我认为这对其他人有帮助。有同样的问题,甚至设置

key: Key(itemId[index]),

没用。然而,

key: UniqueKey(),

非常适合我

关于flutter - 如何修复 flutter 中的 "A dismissed Dismissible widget is still part of the tree."错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55792521/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com