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

插件详情v0.5.1

diffutil_sliverlist

一个使用 diffutil.dart 隐式动画更改的 SliverList。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
3280
喜欢数
61
Pub 分数
140

安装插件

flutter pub add diffutil_sliverlist

插件介绍

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

一个 SliverList 小部件,通过使用 DiffUtil 算法自动动画化项目更改,确保在底层数据列表更改时实现流畅且高效的更新。它利用 diffutil.dart 计算旧列表和新列表之间的最小差异,仅应用必要的动画和重建。适用于大型、动态的可滚动列表,其中性能和视觉流畅性至关重要。该包与 Flutter 的 Sliver 架构无缝集成,并支持所有主要平台。

适合场景

  • 动态可滚动列表,频繁更新
  • 滚动视图中项目的有效重新排序
  • 添加/删除列表项时的平滑过渡
  • 需要优化渲染的大数据集
  • 可滚动界面中的实时数据流

主要特点

  • 列表变化的自动动画
  • 使用 DiffUtil 实现最小更新
  • 大型列表的优化性能
  • 与 Sliver 小部件的无缝集成
  • 跨平台支持所有 Flutter 目标

适合对象

  • 需要流畅列表动画的开发者
  • 具有实时或频繁变化数据的应用程序
  • 对性能敏感的滚动界面
  • 使用基于 Sliver 的布局的 Flutter 开发人员
  • 项目需要最少的样板代码来进行列表差异比较

使用建议

  • 需要理解 DiffUtil 概念
  • 对于非常小的列表,可能有开销
  • 动画行为的自定义有限
  • 依赖外部的 diffutil.dart 包
  • 不适用于非列表型细长类型

原始 README

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

diffutil_sliverlist

Pub Package Build Status codecov

A SliverList that implicitly animates changes.

It supports two use cases:

Animating changes from a list of widgets with unique keys

When you have a list of Widgets and can give each Widget a unique key, you can use DiffUtilSliverList.fromKeyedWidgetList.

See the example code:

class _ExpandableListsState extends State<ExpandableLists> {
  bool expanded = false;

  @override
  Widget build(BuildContext context) {
    return DiffUtilSliverList.fromKeyedWidgetList(
      children: [
        ListTile(
          key: Key("1"),
          title: Text("first"),
          trailing: Icon(Icons.chevron_right),
        ),
        ListTile(
          key: Key("2"),
          title: Text("second"),
          trailing: Icon(Icons.chevron_right),
        ),
        if (this.expanded)
          for (int i = 3; i < 6; i++)
            ListTile(
              key: Key(i.toString()),
              title: Text("index: $i"),
              trailing: Icon(Icons.chevron_right),
            ),
        ListTile(
          key: Key("expand_collapse"),
          onTap: () => setState(() {
            expaned = !expaned;
          }),
          title: Text(expanded ? "collapse" : "expand", style: TextStyle(fontWeight: FontWeight.bold),),
          trailing: Icon(expanded ? Icons.expand_less : Icons.expand_more),
        )
      ],
      insertAnimationBuilder: (context, animation, child) => FadeTransition(
        opacity: animation,
        child: child,
      ),
      removeAnimationBuilder: (context, animation, child) => FadeTransition(
        opacity: animation,
        child: SizeTransition(
          sizeFactor: animation,
          axisAlignment: 0,
          child: child,
        ),
      ),
    );
  }
}

And the result:

Building Widgets from a list of data objects that implement ==

Example:


Widget build(BuildContext context) {
    return CustomScrollView(
             slivers: [
               DiffUtilSliverList<int>(
                 items: list,
                 builder: (context, item) => 
                   Container(
                     color: colors[item % colors.length],
                     height: 48,
                     width: double.infinity,
                 ),
                 insertAnimationBuilder: (context, animation, child) =>
                     FadeTransition(
                       opacity: animation,
                       child: child,
                 ),
                 removeAnimationBuilder: (context, animation, child) =>
                     SizeTransition(
                       sizeFactor: animation,
                       child: child,
                 ),
                 removeAnimationDuration: const Duration(milliseconds: 3000),
                 insertAnimationDuration: const Duration(milliseconds: 1200),
             ),
           ],
         );
}

If list changes, the list will automatically animate new/removed items:

If the items don't implement == correctly, you can pass your own equalityChecker.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目