Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/quire-io/scroll-to-index
scroll to index with fixed/variable row height inside Flutter scrollable widget
https://github.com/quire-io/scroll-to-index
Last synced: 3 months ago
JSON representation
scroll to index with fixed/variable row height inside Flutter scrollable widget
- Host: GitHub
- URL: https://github.com/quire-io/scroll-to-index
- Owner: quire-io
- License: mit
- Created: 2019-04-24T03:41:14.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-04T19:03:30.000Z (8 months ago)
- Last Synced: 2024-07-31T15:01:38.534Z (6 months ago)
- Language: Dart
- Homepage:
- Size: 87.9 KB
- Stars: 503
- Watchers: 16
- Forks: 102
- Open Issues: 26
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-flutter-cn - 滚动到索引 - 为SliverList/ListView滚动到指定索引的子元素,由[Jerry Chen](https://github.com/jerrywell/)开发。 (组件 / UI)
- awesome-flutter - Scroll To Index - scroll to index with fixed/variable row height inside Flutter scrollable widget ` 📝 4 months ago` (UI [🔝](#readme))
- awesome-flutter-cn - Scroll To Index - 滚动到 SliverList/ListView 指定索引的元素,[Jerry Chen](https://github.com/jerrywell/). (组件 / UI)
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:
```yaml
dependencies:
...
scroll_to_index: any
```In your library add the following import:
```dart
import 'package:scroll_to_index/scroll_to_index.dart';
```For help getting started with Flutter, view the online [documentation](https://flutter.io/).
## Usage
This is a widget level library, means you can use this mechanism inside any Flutter scrollable widget.
Example for Flutter ListView
``` dart
ListView(
scrollDirection: scrollDirection,
controller: controller,
children: randomList.map((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
``` dart
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](https://github.com/quire-io/scroll-to-index/blob/master/example/lib/main.dart).
## Who Uses
* [Quire](https://quire.io) - a simple, collaborative, multi-level task management tool.