mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-12 23:45:18 +00:00
chore: fix pagination not working
This commit is contained in:
parent
83172f198c
commit
d22b5349a3
@ -12,6 +12,9 @@ abstract class FamilyPaginatedAsyncNotifier<K, A>
|
||||
Future<void> fetchMore() async {
|
||||
if (state.value == null || !state.value!.hasMore) return;
|
||||
|
||||
final oldState = state.value;
|
||||
|
||||
try {
|
||||
state = AsyncLoadingNext(state.asData!.value);
|
||||
|
||||
final newState = await fetch(
|
||||
@ -24,6 +27,9 @@ abstract class FamilyPaginatedAsyncNotifier<K, A>
|
||||
final items = newState.items.isEmpty ? <K>[] : newState.items.cast<K>();
|
||||
|
||||
state = AsyncData(newState.copyWith(items: <K>[...oldItems, ...items]));
|
||||
} finally {
|
||||
state = AsyncData(oldState!);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<K>> fetchAll() async {
|
||||
@ -56,21 +62,25 @@ abstract class AutoDisposeFamilyPaginatedAsyncNotifier<K, A>
|
||||
|
||||
Future<void> fetchMore() async {
|
||||
if (state.value == null || !state.value!.hasMore) return;
|
||||
final oldState = state.value;
|
||||
|
||||
state = AsyncLoadingNext(state.asData!.value);
|
||||
try {
|
||||
state = AsyncLoadingNext(state.value!);
|
||||
|
||||
state = await AsyncValue.guard(
|
||||
() async {
|
||||
final newState = await fetch(
|
||||
state.value!.nextOffset!,
|
||||
state.value!.limit,
|
||||
);
|
||||
return newState.copyWith(items: [
|
||||
|
||||
state = AsyncData(
|
||||
newState.copyWith(items: [
|
||||
...state.value!.items.cast<K>(),
|
||||
...newState.items.cast<K>(),
|
||||
]);
|
||||
},
|
||||
]),
|
||||
);
|
||||
} finally {
|
||||
state = AsyncData(oldState!);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<K>> fetchAll() async {
|
||||
|
@ -14,6 +14,8 @@ mixin PaginatedAsyncNotifierMixin<K>
|
||||
Future<void> fetchMore() async {
|
||||
if (state.value == null || !state.value!.hasMore) return;
|
||||
|
||||
final oldState = state.value;
|
||||
try {
|
||||
state = AsyncLoadingNext(state.asData!.value);
|
||||
|
||||
final newState = await fetch(
|
||||
@ -26,6 +28,9 @@ mixin PaginatedAsyncNotifierMixin<K>
|
||||
final items = newState.items.isEmpty ? <K>[] : newState.items.cast<K>();
|
||||
|
||||
state = AsyncData(newState.copyWith(items: <K>[...oldItems, ...items]));
|
||||
} finally {
|
||||
state = AsyncData(oldState!);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<K>> fetchAll() async {
|
||||
|
Loading…
Reference in New Issue
Block a user