Search packages, repositories and app categories

Package detailsv3.0.1

scroll_to_index

Scroll to a specific child of any scrollable widget in Flutter

AndroidiOSWebmacOSWindowsLinux
30-day downloads
537K
Likes
821
Pub points
140

Install package

flutter pub add scroll_to_index

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The scroll_to_index package enables precise scrolling to a specific child within any scrollable widget in Flutter, such as ListView or GridView. It provides a simple API to programmatically scroll to an index, making it ideal for navigation within long lists or dynamic content. The package works across all major platforms including Android, iOS, Web, macOS, Windows, and Linux. It is particularly useful when you need to jump to a particular item based on user interaction or state changes. The implementation is lightweight and integrates seamlessly with existing scrollable widgets.

Use cases

  • Jumping to a specific list item
  • Navigating within long scrollable lists
  • Programmatic scrolling in dynamic UIs
  • Improving accessibility in scrollable interfaces
  • Synchronizing scroll position with external events

Key features

  • Scroll to any index by index number
  • Supports all scrollable widgets
  • Cross-platform compatibility
  • Lightweight and easy to integrate
  • Works with dynamic lists

Suitable for

  • Developers building list-heavy apps
  • Apps requiring smooth navigation
  • Accessibility-focused interfaces
  • Dynamic content with frequent updates

Considerations

  • Requires manual handling of scroll controller
  • May need additional logic for smooth animations
  • Not suitable for very large lists without optimization

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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.

Categories

Source repository

Projects using this package