搜尋套件、儲存庫與 APP 分類

套件詳情v0.6.0

implicitly_animated_reorderable_list_2

一個 Flutter ListView,可隱式動畫切換兩個清單之間的變更,並支援重新排序其項目。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2萬
喜歡數
43
Pub 分數
150

安裝套件

flutter pub add implicitly_animated_reorderable_list_2

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,提供可平滑動畫過渡不同清單的 ListView,內建支援項目重新排序。它透過自動處理進入、離開和重新排序動畫,無需明確的動畫控制器,簡化了動態清單互動的實作。適用於需要跨多個平台流暢清單更新與拖曳功能的應用。

適用情境

  • 拖放列表重新排序
  • 動態列表更新帶有流暢的過渡效果
  • 互動式任務或項目管理
  • 即時協作清單編輯
  • 列表修改期間的視覺反饋

主要特色

  • 列表狀態之間的自動動畫
  • 內建的重新排序支援
  • 無需手動動畫控制器
  • 跨平台相容性
  • 最少的樣板程式碼
  • 流暢的進入/退出/重新排序動畫

適合對象

  • 開發互動式列表介面的開發者
  • 需要直覺項目重新排列的應用程式
  • 針對多個平台的專案
  • 重視程式碼潔淨與可維護性的團隊
  • 尋求開箱即用動畫行為的使用者

使用建議

  • 大型列表可能會影響效能
  • 對單個動畫曲線的自訂有限
  • 依賴於底層的 Flutter 渲染管道
  • 不適合複雜的自訂動畫
  • 與其他動畫組件一起使用時,需要仔細管理狀態

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Implicitly Animated Reorderable List

pub package GitHub Stars

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:
  implicitly_animated_reorderable_list_2: ^0.4.2

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_2/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 項

原始碼儲存庫

使用此套件的專案