我在 ListView 中使用 Slidable,所以我可以删除项目。问题是,如果我从列表中删除一个项目,新项目的滑动打开。这显然不是我们想要的行为。这是一个屏幕视频,以便更好地理解。
我的列表是一个 AnimatedList:
` child: AnimatedList(
padding: EdgeInsets.zero,
shrinkWrap: true,
key: listKey,
initialItemCount: widget.month.memories.length,
itemBuilder: (context, index, animation) {
return slideIt(
context,
widget.month.memories[index],
index,
animation,
);
},
),`
这是我的Slidable:
` Widget slideIt(
BuildContext context,
Memory memory,
int index,
animation,
) {
return SlideTransition(
position: Tween<Offset>(
begin: const Offset(-1, 0),
end: Offset(0, 0),
).animate(
CurvedAnimation(
parent: animation,
curve: Curves.easeIn,
reverseCurve: Curves.easeOut,
),
),
child: Slidable(
actionPane: SlidableDrawerActionPane(),
actionExtentRatio: 0.25,
movementDuration: Duration(milliseconds: 400),
child: Column(
children: [
MemoryTile(
memory: memory,
monthName: widget.month.name,
onTapped: () {
_removeMemoryAtIndex(index, memory);
print('tap on ${memory.description}');
},
),
SizedBox(
height: scaleWidth(20),
),
],
),
secondaryActions: [
SlideAction(
closeOnTap: false,
color: AppColors.secondary,
onTap: () => {
_removeMemoryAtIndex(index, memory),
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
CupertinoIcons.trash_fill,
color: AppColors.primary,
size: 30,
),
SizedBox(
height: scaleWidth(5),
),
Text(
'Löschen',
style: AppTextStyles.montserratH6SemiBold,
),
SizedBox(
height: scaleWidth(20),
),
],
),
),
],
),
);
}`
AnimatedList 让它变得更加棘手,所以如果您需要更多信息,请告诉我!我怎样才能解决这个问题?