加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

颤动:ListView中的动画项目删除

发布时间:2020-12-14 14:48:28 所属栏目:百科 来源:网络整理
导读:我正在从Stream构建ListView.我需要为该列表添加删除和插入动画,但不知道如何. 我已经看过Flutter的这个示例,但它与流无关:https://flutter.io/catalog/samples/animated-list/ 任何帮助非常感谢:) new StreamBuilder( stream: feed.stream,// this is a St
我正在从Stream构建ListView.我需要为该列表添加删除和插入动画,但不知道如何.

我已经看过Flutter的这个示例,但它与流无关:https://flutter.io/catalog/samples/animated-list/

任何帮助非常感谢:)

new StreamBuilder(

    stream: feed.stream,// this is a Stream<List<Product>>

    builder: (context,snapshot) {
      if (!snapshot.hasData)
        return const Text('Loading products');
      return new ListView.builder(
          itemCount: snapshot.data.length,itemBuilder: (context,index) {
            Product product = snapshot.data[index];
            return new ProductWidget(product);
          });
    });

解决方法

这不是使用Streams,但作为AnimatedList的一般答案,您可以执行以下操作:

enter image description here

// Remove "Pig" from the list
int removeIndex = 2;

// remove the item from the data list backing the AnimatedList
String removedItem = _data.removeAt(removeIndex);

// This builder is just so that the animation has something
// to work with before it disappears from view since the original
// has already been deleted.
AnimatedListRemovedItemBuilder builder = (context,animation) {
  // A method to build the Card widget.
  return _buildItem(removedItem,animation);
};

// notify the AnimatedList that the item was removed
_listKey.currentState.removeItem(removeIndex,builder);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读