パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v3.0.1

scroll_to_index

Flutter で任意のスクロール可能なウィジェットの特定の子要素にスクロールする

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
53.7万
いいね数
821
Pub ポイント
140

パッケージをインストール

flutter pub add scroll_to_index

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

scroll_to_index パッケージは、Flutter の 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.

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト