djangoflow / list_bloc

BLoC management of simple, filtered, sorted and paged lists.
3 stars 10 forks source link

[list_bloc] Reloading uses current offset to reload, which can return empty list #34

Closed adar2378 closed 12 months ago

adar2378 commented 1 year ago

Currently reloading takes the current state's filter Code Link

  Future<void> reload([F? filter]) => super.load(filter);
  // in data_cubit.dart
  Future<void> load([F? filter]) async {
    final f = filter ?? state.filter;
  // etc...

If the user scrolls to the last item, then after reaching the last item the ContinuousScrollBuilder will take the total item's length as the current offset and try to fetch items. As of this moment, the filter's offset value becomes the length of the items. Code Link

      final offset = _cubit.state.data?.length ?? 0;

Then if we reload the list the cubit will return 0 items and the previously loaded items will vanish due to the wrong offset value.(This offset value is the last items offset after that no items are available to fetch)

adar2378 commented 12 months ago

We can just pass filter with offset 0 to solve it when calling reload method.