我正在尝试创建一个列表,在其中拖动时可以删除其磁贴,因此我使用了 Dismissible 小部件,一切都按我的意愿工作,但是当拖动磁贴以将其关闭时,磁贴重新显示片刻并消失,我的意思的演示显示在这个视频中
FutureBuilder(
future: getMyFavData(),
builder: (context, snapshot) {
if (snapshot.data == null)
return Container(
child: Center(
child: CircularProgressIndicator(
backgroundColor: Colors.red,
)));
else
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
var monthOfProductList =
snapshot.data.elementAt(index)['date'].toDate().month;
var monthNow = DateTime.now().month;
bool newItem = false;
if (monthNow - monthOfProductList == 0) {
newItem = true;
}
return Dismissible(
key: UniqueKey(),
onDismissed: (direction) async {
if (direction == DismissDirection.startToEnd) {
await deleteFromDataBase(
snapshot.data.elementAt(index).documentID);
setState(() {
snapshot.data.remove(index);
});
}
},
background: Container(
color: Colors.red,
child: Row(
children: [
Icon(
Icons.delete_forever,
color: Colors.white,
size: 100,
),
],
),
),
direction: DismissDirection.startToEnd,
child: GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProductFullScreenView(
productInfo: snapshot.data.elementAt(index),
)));
},
child: ProductListCardVerticalFavorite(),
),
);
});
});
我不确定问题出在哪里,任何帮助将不胜感激