【发布时间】:2020-09-12 06:00:18
【问题描述】:
我正在尝试使用动画列表小部件,我想要实现的是通过按下此动画列表内我的磁贴小部件上的按钮,磁贴将从我的数据中删除并从动画列表中删除,但是当按下按钮,最后一项中唯一的最后一项将被删除,而不是给定索引处的一项
首先我为列表使用了一个全局键
final GlobalKey<AnimatedListState> listKey = GlobalKey<AnimatedListState>();
我的动画列表代码
AnimatedList(
initialItemCount: snapshot.data[0].length ,
key: listKey,
itemBuilder: (BuildContext context, int index, Animation animation) {
return SizeTransition(
sizeFactor: animation,
child: GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProductFullScreenView(
productInfo: snapshot.data[0].elementAt(index),
)));
},
child: ProductListCardVertical(
index: index,
),
));
});
在我的小部件中,我调用了这个函数
// function to remove the data from my database, if true then remove the tile
// remove tile
listKey.currentState.removeItem(
widget.index, (context, animation) => Container());
任何帮助将不胜感激
【问题讨论】:
标签: flutter dart flutter-layout flutter-widget