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

套件詳情v3.0.1

scroll_to_index

在 Flutter 中滾動到任何可滾動組件的特定子項

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
53.7萬
喜歡數
821
Pub 分數
140

安裝套件

flutter pub add scroll_to_index

套件介紹

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

scroll_to_index 套件允許在任何可捲動組件(例如 ListView 或 GridView)中精確捲動至特定子項目。它提供簡單的 API,可用程式設計方式捲動至指定索引,非常適合在長清單或動態內容中進行導航。此套件可在所有主要平台(包括 Android、iOS、Web、macOS、Windows 和 Linux)上運作。當您需要根據使用者互動或狀態變更跳轉至特定項目時,特別實用。實作輕量,並與現有的捲動組件無縫整合。

適用情境

  • 跳轉到特定列表項目
  • 在長滾動列表中導航
  • 動態UI中的程式化滾動
  • 改進可存取性在可捲動介面中的應用
  • 與外部事件同步滾動位置

主要特色

  • 透過索引號滾動到任意索引
  • 支援所有可滾動的元件
  • 跨平台相容性
  • 輕量且易於整合
  • 適用於動態清單

適合對象

  • 開發列表密集型應用的開發者
  • 需要順暢導航的應用
  • 面向可存取性的介面
  • 頻繁更新的動態內容

使用建議

  • 需要手動處理滾動控制器
  • 可能需要額外的邏輯來實現流暢的動畫
  • 未優化的情況下,不適合非常大的清單

原始 README

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

scroll-to-index

This package provides the scroll to index mechanism for fixed/variable row height for Flutter scrollable widget.

Getting Started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  scroll_to_index: any

In your library add the following import:

import 'package:scroll_to_index/scroll_to_index.dart';

For help getting started with Flutter, view the online documentation.

Usage

This is a widget level library, means you can use this mechanism inside any Flutter scrollable widget.

Example for Flutter ListView

ListView(
  scrollDirection: scrollDirection,
  controller: controller,
  children: randomList.map<Widget>((data) {
  	final index = data[0];
  	final height = data[1];
    return AutoScrollTag(
      key: ValueKey(index),
      controller: controller,
      index: index,
      child: Text('index: $index, height: $height'),
      highlightColor: Colors.black.withOpacity(0.1),
    );
  }).toList(),
)

you can wrap any of your row widget which has dynamic row height

AutoScrollTag(
  key: ValueKey(index),
  controller: controller,
  index: index,
  child: child
)

with the AutoScrollController controller.

when you need to trigger scroll to a specified index, you can call

controller.scrollToIndex(index, preferPosition: AutoScrollPosition.begin)

even more, with a fixed row height, you can give it a suggested height for more efficient scrolling. there are more configuration.

final controller = AutoScrollController(
  //add this for advanced viewport boundary. e.g. SafeArea
  viewportBoundaryGetter: () => Rect.fromLTRB(0, 0, 0, MediaQuery.of(context).padding.bottom),

  //choose vertical/horizontal
  axis: scrollDirection,

  //this given value will bring the scroll offset to the nearest position in fixed row height case.
  //for variable row height case, you can still set the average height, it will try to get to the relatively closer offset 
  //and then start searching.
  suggestedRowHeight: 200
);

for full example, please see this Demo.

Who Uses

  • Quire - a simple, collaborative, multi-level task management tool.

所屬分類

原始碼儲存庫

使用此套件的專案