![](/img/trans.png)
[英]A dismissed Dismissible widget is still part of the tree. In flutter
[英]A dismissed Dismissible widget is still part of the tree. Getting this error repeatedly after removing item from list
我已将 UniquiId 设置为 Dismissible Widget 的键。 之后添加一些项目,我有些解雇了一个项目。 当我转到下一页时,我收到一个错误(已关闭的 Dismissible 小部件仍然是树的一部分。)即使在已关闭的回调中使用 Provider 从列表中删除项目后也是如此。
@override
Widget build(BuildContext context) {
return Dismissible(
key: UniqueKey(),
direction: DismissDirection.endToStart,
confirmDismiss: (direction) {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Are you sure?'),
content: Text(
'Dou you want to remove the item from the cart?',
),
actions: [
FlatButton(
onPressed: () {
Navigator.of(context).pop(false);
},
child: Text('No'),
),
FlatButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: Text('Yes'),
),
],
),
);
},
onDismissed: (direction) {
Provider.of<Cart>(context, listen: false)
.removeItem(productId);
},
background: Container(
color: Theme.of(context).errorColor,
child: Icon(
Icons.delete,
color: Colors.white,
size: 40,
),
alignment: Alignment.centerRight,
padding: EdgeInsets.only(right: 20),
margin: EdgeInsets.symmetric(
horizontal: 15,
vertical: 4,
),
),
child: Container(
child: Padding(
padding: EdgeInsets.all(8),
child: ListTile(
leading: CircleAvatar(
child: Padding(
padding: EdgeInsets.all(5),
child: FittedBox(
child: Text('\₹${(price * quantity)}'),
),
),
),
title: Text(title),
subtitle: Text(laundryName.toUpperCase()),
trailing: Text('$quantity x'),
),
),
),
);
}
}
请帮助我在这个尝试了很多仍然得到同样的错误。 提前致谢。
确保项目已从根列表中删除。 如果您正在使用提供程序,则通过将 listView.builder 小部件保留在 Consumer 下来获取更新的数据。 这样当您关闭一个项目时,它将被更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.