indexed_list_view 0.0.5

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 89

indexed_list_view #

Similar to a ListView, but lets you programmatically jump to any item, by index. Currently, 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.

Usage #

Import the package #

First, add indexed_list_view as a dependency in your pubspec.yaml

Then, import it:

import 'package:indexed_list_view/indexed_list_view.dart';

Use the package #

First, create an indexed scroll controller:

IndexedScrollController controller = IndexedScrollController();

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

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

To jump, use the controller's jumpToIndex method:

controller.jumpToIndex(10000);

The jump is cheap, since it doesn't need to build all widgets between the old and new positions. However, if all you need is an infinite list, without jumps, there is no need to even define a controller.

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

Don't forget to check the example tab.

TODO #

  • [X] Jump to index.
  • [X] Infinite list (both up and down).
  • [ ] Allow passing lower and upper bounds, so that the list doesn't need to be infinite.
  • [ ] Allow for scrollbars (makes sense in the finite case only).
  • [ ] Make the list trackable, so that you know which item indexes are visible in the top and bottom of the viewport.
  • [ ] Fixing a bug where under certain rare circumstances the user can't stop a ballistic scroll until it stops by itself.

This package got some ideas from Collin Jackson's code in StackOverflow.

Getting Started #

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

For help on editing package code, view the documentation.

[0.0.1] - 14/08/2018

  • Infinite list (both up and down).
  • Jump to index.

[0.0.2] - 14/08/2018

  • Small fixes.
  • Initial animateToIndex.

[0.0.3] - 15/08/2018

  • Small fix.

[0.0.4] - 12/09/2018

  • Removed unnecessary code.

[0.0.5] - 22/02/2012

  • Fixed dart version.

example/main.dart

import 'dart:math';
import 'package:flutter/material.dart';
import 'package:indexed_list_view/indexed_list_view.dart';

void main() {
  runApp(MaterialApp(home: HomePage()));
}

class HomePage extends StatelessWidget {
  static IndexedScrollController controller = IndexedScrollController();

  @override
  Widget build(BuildContext context) {
    //
    return Scaffold(
      appBar: AppBar(title: const Text('Indexed ListView')),
      body: Column(
        children: <Widget>[
          Expanded(
            child: IndexedListView.builder(
              controller: controller,
              itemBuilder: itemBuilder(),
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                MaterialButton(
                  color: Colors.blue,
                  child: const Text("-1000"),
                  onPressed: () => controller.jumpToIndex(controller.startIndex - 1000),
                ),
                MaterialButton(
                  color: Colors.blue,
                  child: const Text("RANDOM"),
                  onPressed: () => controller.jumpToIndex(Random().nextInt(100000)),
                ),
                MaterialButton(
                  color: Colors.blue,
                  child: const Text("+1000"),
                  onPressed: () => controller.jumpToIndex(controller.startIndex + 1000),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Function itemBuilder() {
    //
    final List<double> heights =
        new List<double>.generate(527, (i) => Random().nextInt(200).toDouble() + 30.0);

    return (BuildContext context, int index) {
      //
      return Card(
        child: Container(
          height: heights[index % 527],
          color: Colors.green,
          child: Center(child: Text('ITEM $index')),
        ),
      );
    };
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  indexed_list_view: ^0.0.5

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:indexed_list_view/indexed_list_view.dart';
  
Version Uploaded Documentation Archive
0.0.5 Feb 22, 2019 Go to the documentation of indexed_list_view 0.0.5 Download indexed_list_view 0.0.5 archive
0.0.4 Sep 12, 2018 Go to the documentation of indexed_list_view 0.0.4 Download indexed_list_view 0.0.4 archive
0.0.2 Aug 15, 2018 Go to the documentation of indexed_list_view 0.0.2 Download indexed_list_view 0.0.2 archive
0.0.1 Aug 14, 2018 Go to the documentation of indexed_list_view 0.0.1 Download indexed_list_view 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
81
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
89
Learn more about scoring.

We analyzed this package on May 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.1
  • pana: 0.12.16
  • Flutter: 1.5.4-hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/indexed_list_view.dart.

Run flutter format to format lib/indexed_list_view.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test