【问题标题】:Animated List only delete the last item not the item at the given index动画列表只删除最后一个项目而不是给定索引处的项目
【发布时间】: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


    【解决方案1】:

    更新:

    这个问题发生是因为我没有从列表中删除数据,所以我所做的是我创建了一个全局数据列表并将我从数据库中获取的列表分配给该值,然后我删除了索引磁贴小部件内列表中的项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多