Skip to content

Commit

Permalink
Flutter 3.16.0 compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcglasberg committed Nov 17, 2023
1 parent 67a4ff3 commit 3273e2d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 52 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## [3.0.0] - 2022/11/16

* Flutter 3.16.0 compatible.

## [2.0.2] - 2020/04/14

* Fixed `animateTo()` method which was not using the `duration` and `curve` parameters.
Expand Down
23 changes: 10 additions & 13 deletions README.md
Expand Up @@ -2,11 +2,15 @@

# 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.
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.
It can also animate the scroll, instead of jumping.

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.
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.

In special, this is useful for implementing **calendars**, where you want to be able to jump to
specific dates, as calendars can be scrolled indefinitely, both to the past and future dates.

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
Expand Down Expand Up @@ -132,9 +136,6 @@ explained above.

********

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

*This package got some ideas
from [Collin Jackson's code in StackOverflow](https://stackoverflow.com/questions/44468337/how-can-i-make-a-scrollable-wrapping-view-with-flutter)
, and uses lots of code
Expand Down Expand Up @@ -178,13 +179,9 @@ from [Simon Lightfoot's infinite_listview](https://pub.dev/packages/infinite_lis

* <a href="https://flutter.dev/docs/development/ui/layout/constraints">Understanding constraints</a>

---<br>_Marcelo Glasberg:_<br>
<br>_Marcelo Glasberg:_<br>
_https://github.com/marcglasberg_<br>
_https://linkedin.com/in/marcglasberg/_<br>
_https://linkedin.com/in/marcglasberg_<br>
_https://twitter.com/glasbergmarcelo_<br>
_https://stackoverflow.com/users/3411681/marcg_<br>
_https://medium.com/@marcglasberg_<br>




19 changes: 1 addition & 18 deletions analysis_options.yaml
Expand Up @@ -354,17 +354,10 @@ linter:
# https://dart-lang.github.io/linter/lints/implementation_imports.html
- implementation_imports

# Although there are some false positives, this lint generally catches unnecessary checks
# - https://github.com/dart-lang/linter/issues/811
#
# pedantic: disabled
# https://dart-lang.github.io/linter/lints/invariant_booleans.html
- invariant_booleans

# Type check for Iterable<T>.contains(other) where other is! T
# otherwise contains will always report false. Those errors are usually very hard to catch.
# https://dart-lang.github.io/linter/lints/iterable_contains_unrelated_type.html
- iterable_contains_unrelated_type
- collection_methods_unrelated_type

# Hint to join return and assignment.
# pedantic: disabled
Expand Down Expand Up @@ -399,11 +392,6 @@ linter:
# https://dart-lang.github.io/linter/lints/lines_longer_than_80_chars.html
# - lines_longer_than_80_chars

# Type check for List<T>.remove(item) where item is! T
# The list can't contain item. Those errors are not directly obvious especially when refactoring.
# https://dart-lang.github.io/linter/lints/list_remove_unrelated_type.html
- list_remove_unrelated_type

# Good for libraries to prevent unnecessary code paths.
# False positives may occur for applications when boolean properties are generated by external programs
# producing auto-generated source code
Expand Down Expand Up @@ -546,11 +534,6 @@ linter:
# https://dart-lang.github.io/linter/lints/prefer_double_quotes.html
# - prefer_double_quotes

# Prevent confusion with call-side when using named parameters
# pedantic: enabled
# https://dart-lang.github.io/linter/lints/prefer_equal_for_default_values.html
- prefer_equal_for_default_values

# Single line methods + implementation makes it hard to write comments for that line.
# Dense code isn't necessarily better code.
# pedantic: disabled
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Expand Up @@ -4,7 +4,7 @@ publish_to: "none"
version: 1.0.0+1

environment:
sdk: '>=2.13.0 <3.0.0'
sdk: '>=3.0.0 <4.0.0'

dependencies:
flutter:
Expand Down
20 changes: 3 additions & 17 deletions lib/indexed_list_view.dart
Expand Up @@ -10,10 +10,8 @@ import 'package:flutter/widgets.dart';
// Based upon package infinite_list_view by Simon Lightfoot.
// For more info, see: https://pub.dartlang.org/packages/indexed_list_view

/// Indexed List View
///
/// ListView that lets you jump instantly to any index.
/// Only works for lists with infinite extent.
/// A ListView that lets you jump instantly or animate to any list item, by index.
/// Important: Only works for lists with infinite extent.
class IndexedListView extends StatefulWidget {
/// See [ListView.builder]
IndexedListView.builder({
Expand Down Expand Up @@ -144,15 +142,11 @@ class IndexedListView extends StatefulWidget {
_IndexedListViewState createState() => _IndexedListViewState();
}

// -------------------------------------------------------------------------------------------------

/// The builder should create a widget for the given index.
/// When the builder returns `null`, the list will ask the `emptyItemBuilder`
/// to create an "empty" item to be displayed instead.
typedef IndexedWidgetBuilderOrNull = Widget? Function(BuildContext context, int index);

// -------------------------------------------------------------------------------------------------

class _IndexedListViewState extends State<IndexedListView> {
//
@override
Expand Down Expand Up @@ -193,7 +187,7 @@ class _IndexedListViewState extends State<IndexedListView> {
viewportBuilder: (BuildContext context, ViewportOffset offset) {
return Builder(builder: (BuildContext context) {
// Build negative [ScrollPosition] for the negative scrolling [Viewport].
final state = Scrollable.of(context)!;
final state = Scrollable.of(context);
final negativeOffset = _IndexedScrollPosition(
physics: scrollPhysics,
context: state,
Expand Down Expand Up @@ -273,8 +267,6 @@ class _IndexedListViewState extends State<IndexedListView> {
}
}

// -------------------------------------------------------------------------------------------------

class _AlwaysScrollableScrollPhysics extends ScrollPhysics {
/// Creates scroll physics that always lets the user scroll.
const _AlwaysScrollableScrollPhysics({ScrollPhysics? parent}) : super(parent: parent);
Expand All @@ -288,8 +280,6 @@ class _AlwaysScrollableScrollPhysics extends ScrollPhysics {
bool shouldAcceptUserOffset(ScrollMetrics position) => true;
}

// -------------------------------------------------------------------------------------------------

/// Provides scroll with infinite bounds, and keeps a scroll-position and a origin-index.
/// The scroll-position is the number of pixels of scroll, considering the item at origin-index
/// as the origin (0.0). So, for example, if you have scroll-position 10.0 and origin-index 15,
Expand Down Expand Up @@ -498,8 +488,6 @@ class IndexedScrollController extends ScrollController {
}
}

// -------------------------------------------------------------------------------------------------

class _IndexedScrollPosition extends ScrollPositionWithSingleContext {
_IndexedScrollPosition({
required ScrollPhysics physics,
Expand Down Expand Up @@ -527,5 +515,3 @@ class _IndexedScrollPosition extends ScrollPositionWithSingleContext {
@override
double get maxScrollExtent => double.infinity;
}

// -------------------------------------------------------------------------------------------------
6 changes: 3 additions & 3 deletions pubspec.yaml
@@ -1,11 +1,11 @@
name: indexed_list_view
description: Infinite ListView that lets you programmatically jump instantly to any item, by index. Performant for lists of any size.
version: 2.0.2
version: 3.0.0
# author: Marcelo Glasberg <marcglasberg@gmail.com>
homepage: https://github.com/marcglasberg/indexed_list_view

environment:
sdk: '>=2.13.0 <3.0.0'
sdk: '>=3.0.0 <4.0.0'

dependencies:
flutter:
Expand All @@ -14,5 +14,5 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter

flutter:

0 comments on commit 3273e2d

Please sign in to comment.