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

transformable_list_view 封面
套件詳情v0.8.0

transformable_list_view

擴展預設 ListView 的小部件,可根據其滾動位置新增項目變換動畫

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
212
喜歡數
133
Pub 分數
150

安裝套件

flutter pub add transformable_list_view

套件介紹

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

一個擴展 ListView 的 Flutter 小部件,可根據清單項目之滾動位置實現平滑的變換動畫。它允許開發者創建動態、互動式清單,並在項目進入或離開視口時加入縮放、旋轉或淡入淡出等視覺效果。非常適合用於增強滾動密集型介面的使用者體驗。此套件支援所有主要平台,包括 Android、iOS、Web、macOS、Windows 與 Linux。

適用情境

  • 建立動畫滾動清單
  • 透過滾動觸發的變換增強使用者介面
  • 建構吸引人的產品輪播
  • 設計沉浸式內容流
  • 實現類似視差的效果
  • 滾動時添加視覺反饋

主要特色

  • 基於滾動位置的項目變換
  • 平滑的動畫過渡
  • 跨平台相容性
  • 與現有 ListView 程式碼的輕鬆整合
  • 支援縮放、旋轉與不透明度變更
  • 可自訂的動畫曲線與時序

適合對象

  • 尋求互動元件的UI設計師
  • 開發滾動驅動動畫的開發者
  • 需要引人入勝的列表互動的應用程式
  • 針對多個平台的專案
  • 專注於打造精緻使用者體驗的團隊

使用建議

  • 在大型資料集上可能會影響效能
  • 需要仔細調整動畫參數
  • 最適合中等大小的清單
  • 不適合高度複雜的動畫
  • 需要在不同設備和平台進行測試

原始 README

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

Scrollable widgets with easily customizable transform animations.

Features

The package contains 3 widgets:

  • TransformableListView that extends ListView
  • TransformableSliverList that extends SliverList
  • TransformableSliver that extends SliverToBoxAdapter

Each of then has getTransformMatrix callback. In the callback you need to return Matrix4 that represetns transormation of the child at the current moment. If you don't need any transformations you can simply return Matrix4.identity().

In getTransformMatrix callback you receive TransformableListItem with the data about list item:

  • Offset offset is main axis offset of the child. By default (with vertical, non reversed scroll view) offset.dx is always 0 while offset.dy is the distance between top edge of the child and top edge of the viewport.
  • Size size is the child size received from its RenderBox.
  • SliverConstraints constraints describes the current scroll state of the viewport from the point of view of the sliver receiving the constraints.
  • int? index is the index of the child. Will be null when using TransformableSliver.
  • TransformableListItemPosition position is child position on the main axis viewport. Can be .topEdge, .middle or .bottomEdge.
  • double visibleExtent is currently visible portion of item. For example, if item is hidden it will be 0 while it's completely displayed will equal to size.height or size.width depending on axis.

Usage

First you need to add TransformableListView where you need transformations

TransformableListView.builder(
  getTransformMatrix: getTransformMatrix,
  itemBuilder: (context, index) {
    return Container(
      height: 100,
      margin: const EdgeInsets.symmetric(
        horizontal: 16,
        vertical: 4,
      ),
      decoration: BoxDecoration(
        color: index.isEven ? Colors.grey : Colors.blueAccent,
        borderRadius: BorderRadius.circular(20),
      ),
      alignment: Alignment.center,
      child: Text(index.toString()),
    );
  },
  itemCount: 30,
),

Second you need to implement getTransformMatrix callback

Matrix4 getTransformMatrix(TransformableListItem item) {
  /// final scale of child when the animation is completed
  const endScaleBound = 0.3;

  /// 0 when animation completed and [scale] == [endScaleBound]
  /// 1 when animation starts and [scale] == 1
  final animationProgress = item.visibleExtent / item.size.height;

  /// result matrix
  final paintTransform = Matrix4.identity();

  /// animate only if item is on edge
  if (item.position != TransformableListItemPosition.middle) {
    final scale = endScaleBound + ((1 - endScaleBound) * animationProgress);

    paintTransform
      ..translate(item.size.width / 2)
      ..scale(scale)
      ..translate(-item.size.width / 2);
  }

  return paintTransform;
}

You can implement your own callback or check more at /example folder.

Additional information

You can read more about matrix transfomations in Flutter here. Any feedback and PRs are welcome.

Developed by TBR Group.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。