🐛 Fix the paging refreshing issue
This commit is contained in:
@@ -8,6 +8,7 @@ abstract class PaginationController<T> {
|
|||||||
|
|
||||||
bool get fetchedAll;
|
bool get fetchedAll;
|
||||||
bool get isLoading;
|
bool get isLoading;
|
||||||
|
bool get isReloading;
|
||||||
bool get hasMore;
|
bool get hasMore;
|
||||||
set hasMore(bool value);
|
set hasMore(bool value);
|
||||||
String? get cursor;
|
String? get cursor;
|
||||||
@@ -32,7 +33,7 @@ mixin AsyncPaginationController<T> on AsyncNotifier<List<T>>
|
|||||||
int? totalCount;
|
int? totalCount;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get fetchedCount => state.value?.length ?? 0;
|
int get fetchedCount => isReloading ? 0 : state.value?.length ?? 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get fetchedAll =>
|
bool get fetchedAll =>
|
||||||
@@ -41,6 +42,9 @@ mixin AsyncPaginationController<T> on AsyncNotifier<List<T>>
|
|||||||
@override
|
@override
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool isReloading = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool hasMore = true;
|
bool hasMore = true;
|
||||||
|
|
||||||
@@ -56,6 +60,7 @@ mixin AsyncPaginationController<T> on AsyncNotifier<List<T>>
|
|||||||
@override
|
@override
|
||||||
Future<void> refresh() async {
|
Future<void> refresh() async {
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
|
isReloading = true;
|
||||||
totalCount = null;
|
totalCount = null;
|
||||||
hasMore = true;
|
hasMore = true;
|
||||||
cursor = null;
|
cursor = null;
|
||||||
@@ -64,8 +69,9 @@ mixin AsyncPaginationController<T> on AsyncNotifier<List<T>>
|
|||||||
final newState = await AsyncValue.guard<List<T>>(() async {
|
final newState = await AsyncValue.guard<List<T>>(() async {
|
||||||
return await fetch();
|
return await fetch();
|
||||||
});
|
});
|
||||||
state = newState;
|
isReloading = false;
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
|
state = newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -81,8 +87,8 @@ mixin AsyncPaginationController<T> on AsyncNotifier<List<T>>
|
|||||||
return [...?state.value, ...elements];
|
return [...?state.value, ...elements];
|
||||||
});
|
});
|
||||||
|
|
||||||
state = newState;
|
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
|
state = newState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +98,7 @@ mixin AsyncPaginationFilter<F, T> on AsyncPaginationController<T>
|
|||||||
Future<void> applyFilter(F filter) async {
|
Future<void> applyFilter(F filter) async {
|
||||||
if (currentFilter == filter) return;
|
if (currentFilter == filter) return;
|
||||||
// Reset the data
|
// Reset the data
|
||||||
|
isReloading = true;
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
totalCount = null;
|
totalCount = null;
|
||||||
hasMore = true;
|
hasMore = true;
|
||||||
@@ -102,7 +109,8 @@ mixin AsyncPaginationFilter<F, T> on AsyncPaginationController<T>
|
|||||||
final newState = await AsyncValue.guard<List<T>>(() async {
|
final newState = await AsyncValue.guard<List<T>>(() async {
|
||||||
return await fetch();
|
return await fetch();
|
||||||
});
|
});
|
||||||
state = newState;
|
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
|
isReloading = false;
|
||||||
|
state = newState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user