Closed carrasc0 closed 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.
I'll try to have a look at it during the weekend. This was working ok, so probably some recent Flutter version changed something.
@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]);
}
@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?
Closing this. Will reopen if more info becomes available.
Facing the same error. The fix didn't work
@danger-ahead Could you please provide me with the code for your itemBuilder
?
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).
To anyone reaching this issue:
itemBuilder
should be able to deal with any index
.itemBuilder
may return null. In that case, the emptyItemBuilder
callback will return an "empty" item to be displayed instead. As default, this will return empty containers.Hope this helps!
any update for finite list?
@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.
Throwing this exception with the provided example. I guess because itemCount is not provided