part of '../../spotify.dart'; typedef PseudoPaginatedProps = ({ List items, int nextOffset, bool hasMore, }); abstract class FamilyPaginatedAsyncNotifier< K, T extends BasePaginatedState, A> extends FamilyAsyncNotifier with SpotifyMixin { Future> fetch(A arg, int offset, int limit); Future fetchMore() async { if (state.value == null || !state.value!.hasMore) return; state = AsyncLoadingNext(state.asData!.value); state = await AsyncValue.guard( () async { final (:items, :hasMore, :nextOffset) = await fetch( arg, state.value!.offset, state.value!.limit, ); return state.value!.copyWith( hasMore: hasMore, items: [ ...state.value!.items, ...items, ], offset: nextOffset, ) as T; }, ); } Future> fetchAll() async { if (state.value == null) return []; if (!state.value!.hasMore) return state.value!.items; bool hasMore = true; while (hasMore) { await update((state) async { final res = await fetch( arg, state.offset, state.limit, ); hasMore = res.hasMore; return state.copyWith( items: [...state.items, ...res.items], offset: res.nextOffset, hasMore: hasMore, ) as T; }); } return state.value!.items; } } abstract class AutoDisposeFamilyPaginatedAsyncNotifier< K, T extends BasePaginatedState, A> extends AutoDisposeFamilyAsyncNotifier with SpotifyMixin { Future> fetch(A arg, int offset, int limit); Future fetchMore() async { if (state.value == null || !state.value!.hasMore) return; state = AsyncLoadingNext(state.asData!.value); state = await AsyncValue.guard( () async { final (:items, :hasMore, :nextOffset) = await fetch( arg, state.value!.offset, state.value!.limit, ); return state.value!.copyWith( hasMore: hasMore, items: [ ...state.value!.items, ...items, ], offset: nextOffset, ) as T; }, ); } Future> fetchAll() async { if (state.value == null) return []; if (!state.value!.hasMore) return state.value!.items; bool hasMore = true; while (hasMore) { await update((state) async { final res = await fetch( arg, state.offset, state.limit, ); hasMore = res.hasMore; return state.copyWith( items: [...state.items, ...res.items], offset: res.nextOffset, hasMore: hasMore, ) as T; }); } return state.value!.items; } }