marcglasberg / indexed_list_view

Flutter package: Similar to a ListView, but lets you programmatically jump to any item, by index.
BSD 2-Clause "Simplified" License
251 stars 21 forks source link

RangeError (index): Invalid value: Not in inclusive range 0..3: 4 #34

Closed carrasc0 closed 2 years ago

carrasc0 commented 2 years ago

Throwing this exception with the provided example. I guess because itemCount is not provided

yasirrose commented 2 years ago

I am trying to paginate the list using indexed_list_view but getting the "RangeError (index): Invalid value: Not in inclusive range 0..9" error on loading data.

marcglasberg commented 2 years ago

I'll try to have a look at it during the weekend. This was working ok, so probably some recent Flutter version changed something.

marcglasberg commented 2 years ago

@carrasc0 @yasirrose

The itemBuilder has this signature:

typedef IndexedWidgetBuilderOrNull = Widget? Function(BuildContext context, int index);

The list is infinite. This means you can just pass the index to a list. For example, if your list has 100 items, it will fail when index is > 100 or < 0. What you need to do is check the index. For example:

List<String> myList = [...];

Widget? Function(BuildContext context, int index) {
if (index<0 || index >= myList.length) return null;
else return Text(myList[index]);
}
marcglasberg commented 2 years ago

@carrasc0

Please, which provided example? I tried these:

main.dart
main_page_storage_key.dart
main_with_finite_items.dart
main_with_item_count.dart

I can't see it throw any exceptions with those? Could you please help me reproduce the problem?

marcglasberg commented 2 years ago

Closing this. Will reopen if more info becomes available.

danger-ahead commented 2 years ago

Facing the same error. The fix didn't work

marcglasberg commented 2 years ago

@danger-ahead Could you please provide me with the code for your itemBuilder?

danger-ahead commented 2 years ago

Umm sorry. I am not using this library any more. But the problem was exactly what has been mentioned by the issue opener. The children widgets were okay. But I could scroll both up and down beyond the actual children widgets (actually resulted in red the usual red areas that arise when there's an error).

marcglasberg commented 2 years ago

To anyone reaching this issue:

Hope this helps!

kevin4dhd commented 1 month ago

any update for finite list?

marcglasberg commented 1 month ago

@kevin4dhd No, this widget is for infinite lists only, and that won't change. For finite lists you can maybe try https://pub.dev/packages/scrollable_positioned_list or search some other widget.