搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案