• Stars
    star
    248
  • Rank 162,595 (Top 4 %)
  • Language
    Dart
  • License
    BSD 2-Clause "Sim...
  • Created about 6 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flutter package: Similar to a ListView, but lets you programmatically jump to any item, by index.

pub package

indexed_list_view

Similar to a ListView, but lets you programmatically jump to any item, by index. The index jump happens instantly, no matter if you have millions of items.

Limitation: The list is always infinite both to positive and negative indexes. In other words, it can be scrolled indefinitely both to the top and to the bottom.

You can define index bounds by giving it a minItemCount and maxItemCount, but this will not prevent the list from scrolling indefinitely. When showing items out of the index bounds, or when your itemBuilder returns null, it will ask the emptyItemBuilder to create an "empty" item to be displayed instead. As default, this will return empty containers.

Usage

Import the package

Add indexed_list_view as a dependency in your pubspec.yaml file, and then import it:

import 'package:indexed_list_view/indexed_list_view.dart';

Use the package

First, create an indexed scroll controller:

var controller = IndexedScrollController();

Optionally, you may setup an initial index and/or initial scroll offset:

var controller = IndexedScrollController(
    initialIndex: 75,
    initialScrollOffset : 30.0);    

Then, create the indexed list view, and pass it the controller:

IndexedListView.builder(
    controller: controller, 
    itemBuilder: itemBuilder);

There is also the separated constructor, same as ListView.separated:

IndexedListView.separated(
    controller: controller, 
    itemBuilder: itemBuilder,
    separatorBuilder: separatorBuilder);

To jump, use the controller methods like jumpToIndex :

controller.jumpToIndex(10000);

Details

The IndexedScrollController has not only an offset in pixels, but also an origin-index that indicates which item is considered to be at the offset position 0.0.

So there are two ways for you to move the list programmatically: You can change only the offset, or else change the originIndex and the offset at the same time.

To change the originIndex you make an "index jump". This jump is cheap, since it doesn't need to build all widgets between the old and new positions. It will just change the origin.

If you want to move the list programmatically you must create a scroll controller of type IndexedScrollController and pass it in the list constructor. However, if all you need is an infinite list without jumps, then there is no need to even create a controller.

You move the list programmatically by calling the controller methods.

Controller Methods

  1. jumpToIndex(index)

    The is the most common method for you to use. It jumps the origin-index to the given index, and the scroll-position to 0.0.

  2. jumpToIndexAndOffset(index, offset)

    Jumps the origin-index to the given index, and the scroll-position to offset, without animation.

  3. animateToIndex(index)

    If the current origin-index is already the same as the given index, animates the position from its current value to the offset position relative to the origin-index.

    However, if the current origin-index is different from the given index, this will jump to the new index, without any animation. In general, there are never animations when the index changes.

  4. animateToIndexAndOffset(index, offset)

    Same as animateToIndex() but also lets you specify the new offset.

  5. jumpTo(offset)

    Goes to origin-index "0", and then jumps the scroll position from its current value to the given offset, without animation.

  6. animateTo(offset)

    If the current origin-index is already "0", animates the position from its current value to the offset position.

    However, if the current origin-index is different from "0", this will jump to index "0" and the given offset, without any animation. In general, there are never animations when the index changes.

  7. jumpToWithSameOriginIndex(offset)

    Jumps the offset, relative to the current origin-index.

  8. animateToWithSameOriginIndex(offset)

    Animates the offset, relative to the current origin-index.

  9. jumpToRelative(offset)

    Jumps the offset, adding or subtracting from the current offset. It keeps the same origin-index.

  10. animateToRelative(offset)

    Animates the offset, adding or subtracting from the current offset. It keeps the same origin-index.

Don't forget to check the example tab. It shows an infinite list of items of different heights, and you may tap buttons to run some of the methods explained above.


Hopefully this widget will become obsolete when Flutter's original ListView allows for negative indexes and for indexed jumps. See: flutter/flutter#12319

This package got some ideas from Collin Jackson's code in StackOverflow , and uses lots of code from Simon Lightfoot's infinite_listview.

The Flutter packages I've authored:

My Medium Articles:

My article in the official Flutter documentation:

---
Marcelo Glasberg:
https://github.com/marcglasberg
https://linkedin.com/in/marcglasberg/
https://twitter.com/glasbergmarcelo
https://stackoverflow.com/users/3411681/marcg
https://medium.com/@marcglasberg

More Repositories

1

i18n_extension

Flutter package: Easy and powerful internationalization using Dart extensions.
Dart
290
star
2

async_redux

Flutter Package: A Redux version tailored for Flutter, which is easy to learn, to use, to test, and has no boilerplate. Allows for both sync and async reducers.
Dart
223
star
3

fast_immutable_collections

Dart Package: Immutable lists, sets, maps, and multimaps, which are as fast as their native mutable counterparts. Extension methods and comparators for native Dart collections.
Dart
188
star
4

assorted_layout_widgets

Flutter package: Assorted layout widgets that boldly go where no native Flutter widgets have gone before.
Dart
138
star
5

back_button_interceptor

Flutter Package: May be used to intercept the Android back-button, as an alternative to `WillPopScope`.
Dart
100
star
6

flutter_layout_article

Flutter Article: The Advanced Layout Rule Even Beginners Must Know
Dart
92
star
7

align_positioned

Flutter Package: When your desired layout or animation is too complex for Columns and Rows, this widget lets you position/size/rotate/transform its child in complex ways.
Dart
75
star
8

network_to_file_image

Flutter Package: This is a mixture of FileImage and NetworkImage. It will download the image from the url once, save it locally in the file system, and then use it from there in the future.
Dart
60
star
9

matrix4_transform

Flutter package: Helper math class for easily creating Matrix4 transformations, that you can use in Container's transform parameter and elsewhere.
Dart
52
star
10

animated_size_and_fade

Flutter Package: A widget that does a fade and size transition between widgets of same width but different heights, and you don't need to know their sizes in advance.
Dart
43
star
11

provider_for_redux

Flutter Package: Let's you use Provider with Redux.
Dart
24
star
12

themed

Flutter package: Define a theme (colors, text styles etc.) as static const values which can be changed dynamically. Also comes with useful extensions to create text styles by composition.
Dart
24
star
13

image_pixels

Flutter Package: Lets you extend the background color of an image, or else build any widget that depends on the image width/height, and the color of its pixels.
Dart
23
star
14

weak_map

Dart package: WeakMap is a map where the keys are weakly referenced. WeakContainer lets you check if an object is the same you had before. This package also contains cache functions for memoization done right, with weak-references.
Dart
20
star
15

bdd_framework

Dart package: BDD framework for Dart/Flutter. Lets you create BDD tests in code, and gives you easy to read error messages when assertions fail. Exports to Gherkin/Cucumber feature files.
Dart
12
star
16

redux_app_example

Complete Flutter app example, with AsyncRedux state management. Can also be used as a template to start a new project.
Dart
7
star
17

HibernateInspectionsPlugin

Initial Setup version 1.0
Java
3
star
18

marcelosdartplugin

Dart and Flutter plugin to add features to the IntelliJ IDE.
Java
3
star
19

SameAppDifferentTech

This project contains the SAME MOBILE APP implemented with DIFFERENT tech stacks: React Native, Flutter, Android, iOS.
TypeScript
2
star
20

bdd_framework_for_jest

BDD framework for Jest (JavaScript / TypeScript / React / React Native). Lets you create BDD tests in code, and gives you easy to read error messages when assertions fail. Exports to Gherkin/Cucumber feature files.
JavaScript
1
star
21

flutter_hooks_async_redux

Combines flutter_hooks and async_redux packages to add Redux to flutter_hooks.
Dart
1
star