mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: common ctr
opt: state Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -5,4 +5,28 @@ import 'package:get/get.dart';
|
||||
abstract class CommonDataController<R, T> extends CommonController<R, T> {
|
||||
@override
|
||||
Rx<LoadingState<T>> loadingState = LoadingState<T>.loading().obs;
|
||||
|
||||
@override
|
||||
Future<void> queryData([bool isRefresh = true]) async {
|
||||
if (isLoading) return;
|
||||
isLoading = true;
|
||||
LoadingState<R> response = await customGetData();
|
||||
if (response is Success<R>) {
|
||||
if (!customHandleResponse(isRefresh, response)) {
|
||||
loadingState.value = response as LoadingState<T>;
|
||||
}
|
||||
} else {
|
||||
if (isRefresh &&
|
||||
!handleError(response is Error ? response.errMsg : null)) {
|
||||
loadingState.value = response as LoadingState<T>;
|
||||
}
|
||||
}
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onReload() {
|
||||
loadingState.value = LoadingState<T>.loading();
|
||||
return super.onReload();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user