搜索插件、代码仓与 APP 分类

animated_list_plus 封面
插件详情v0.5.2

animated_list_plus

一个 Flutter ListView,可在两个列表之间隐式动画切换,并支持重新排序其项目。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
3.5万
喜欢数
198
Pub 分数
150

安装插件

flutter pub add animated_list_plus

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

AnimatedListPlus 是一个 Flutter 包,通过在列表更改时提供隐式动画来扩展 ListView 的功能,包括项目添加、删除和重新排序时的平滑过渡。它通过内置的动画支持简化了动态列表的实现,确保跨平台的流畅用户体验。该包支持所有主要的 Flutter 平台,并可轻松集成到现有项目中,设置简单。它通过自动处理动画状态来增强列表交互,无需手动动画控制器。

适合场景

  • 动态列表更新并带有视觉反馈
  • 表单或任务管理器中的可重新排序项目列表
  • 聊天或动态界面中的平滑过渡
  • 交互式待办事项应用程序
  • 仪表板中的实时数据展示

主要特点

  • 列表变化的隐式动画
  • 内置的项目重新排序支持
  • 跨平台兼容性
  • 最少的样板代码
  • 自动动画状态管理
  • 可自定义的动画曲线

适合对象

  • 开发交互式列表界面的开发者
  • 需要实时列表更新的应用
  • 强调流畅用户体验过渡的项目
  • 希望减少动画复杂性的团队
  • Flutter 初学者探索高级列表功能

使用建议

  • 在非常大的列表上可能会影响性能
  • 需要仔细处理项目键
  • 对复杂动画逻辑的自定义有限
  • 不太适合高度自定义的动画序列
  • 最适合中等大小的数据集

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Animated List Plus

Resurrection of the discontinued implicitly_animated_reorderable_list Plugin.

A Flutter ListView that implicitly calculates the changes between two lists using the MyersDiff algorithm and animates between them for you. The ImplicitlyAnimatedReorderableList adds reordering support to its items with fully custom animations.

Demo

Click here to view the full example.

Installing

Add it to your pubspec.yaml file:

dependencies:
  animated_list_plus: ^0.4.3

Install packages from the command line

flutter packages get

If you like this package, consider supporting it by giving it a star on GitHub and a like on pub.dev :heart:

Usage

The package contains two ListViews: ImplicitlyAnimatedList which is the base class and offers implicit animation for item insertions, removals as well as updates, and ImplicitlyAnimatedReorderableList which extends the ImplicitlyAnimatedList and adds reordering support to its items. See examples below on how to use them.

ImplicitlyAnimatedList

ImplicitlyAnimatedList is based on AnimatedList and uses the MyersDiff algorithm to calculate the difference between two lists and calls insertItem and removeItem on the AnimatedListState for you.

Example
// Specify the generic type of the data in the list.
ImplicitlyAnimatedList<MyGenericType>(
  // The current items in the list.
  items: items,
  // Called by the DiffUtil to decide whether two object represent the same item.
  // For example, if your items have unique ids, this method should check their id equality.
  areItemsTheSame: (a, b) => a.id == b.id,
  // Called, as needed, to build list item widgets.
  // List items are only built when they're scrolled into view.
  itemBuilder: (context, animation, item, index) {
    // Specifiy a transition to be used by the ImplicitlyAnimatedList.
    // See the Transitions section on how to import this transition.
    return SizeFadeTransition(
      sizeFraction: 0.7,
      curve: Curves.easeInOut,
      animation: animation,
      child: Text(item.name),
    );
  },
  // An optional builder when an item was removed from the list.
  // If not specified, the List uses the itemBuilder with
  // the animation reversed.
  removeItemBuilder: (context, animation, oldItem) {
    return FadeTransition(
      opacity: animation,
      child: Text(oldItem.name),
    );
  },
);

If you have a CustomScrollView you can use the SliverImplicitlyAnimatedList.

As AnimatedList doesn't support item moves, a move is handled by removing the item from the old index and inserting it at the new index.

ImplicitlyAnimatedReorderableList

ImplicitlyAnimatedReorderableList is based on ImplicitlyAnimatedList and adds reordering support to the list.

Example
ImplicitlyAnimatedReorderableList<MyGenericType>(
  items: items,
  areItemsTheSame: (oldItem, newItem) => oldItem.id == newItem.id,
  onReorderFinished: (item, from, to, newItems) {
    // Remember to update the underlying data when the list has been
    // reordered.
    setState(() {
      items
        ..clear()
        ..addAll(newItems);
    });
  },
  itemBuilder: (context, itemAnimation, item, index) {
    // Each item must be wrapped in a Reorderable widget.
    return Reorderable(
      // Each item must have an unique key.
      key: ValueKey(item),
      // The animation of the Reorderable builder can be used to
      // change to appearance of the item between dragged and normal
      // state. For example to add elevation when the item is being dragged.
      // This is not to be confused with the animation of the itemBuilder.
      // Implicit animations (like AnimatedContainer) are sadly not yet supported.
      builder: (context, dragAnimation, inDrag) {
        final t = dragAnimation.value;
        final elevation = lerpDouble(0, 8, t);
        final color = Color.lerp(Colors.white, Colors.white.withOpacity(0.8), t);

        return SizeFadeTransition(
          sizeFraction: 0.7,
          curve: Curves.easeInOut,
          animation: itemAnimation,
          child: Material(
            color: color,
            elevation: elevation,
            type: MaterialType.transparency,
            child: ListTile(
              title: Text(item.name),
              // The child of a Handle can initialize a drag/reorder.
              // This could for example be an Icon or the whole item itself. You can
              // use the delay parameter to specify the duration for how long a pointer
              // must press the child, until it can be dragged.
              trailing: Handle(
                delay: const Duration(milliseconds: 100),
                child: Icon(
                  Icons.list,
                  color: Colors.grey,
                ),
              ),
            ),
          ),
        );
      },
    );
  },
  // Since version 0.2.0 you can also display a widget
  // before the reorderable items...
  header: Container(
    height: 200,
    color: Colors.red,
  ),
  // ...and after. Note that this feature - as the list itself - is still in beta!
  footer: Container(
    height: 200,
    color: Colors.green,
  ),
  // If you want to use headers or footers, you should set shrinkWrap to true
  shrinkWrap: true,
);

For a more in depth example click here.

Transitions

You can use some custom transitions (such as the SizeFadeTransition) for item animations by importing the transitions pack:

import 'package:implicitly_animated_reorderable_list/transitions.dart';

If you want to contribute your own custom transitions, feel free to make a pull request.

Caveats

Note that this package is still in its very early phase and not enough testing has been done to guarantee stability.

Also note that computing the diff between two very large lists may take a significant amount of time (the computation is done on a background isolate though unless spawnIsolate is set to false).

Acknowledgements

The diff algorithm that ImplicitlyAnimatedList uses was written by Dawid Bota at GitLab.

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目