mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refactor: reply
This commit is contained in:
@@ -12,10 +12,14 @@ abstract class CommonController extends GetxController {
|
||||
|
||||
Future<LoadingState> customGetData();
|
||||
|
||||
List? handleResponse(List currentList, List dataList) {
|
||||
List? handleListResponse(List currentList, List dataList) {
|
||||
return null;
|
||||
}
|
||||
|
||||
bool customHandleResponse(Success response) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void handleSuccess(List currentList, List dataList) {}
|
||||
|
||||
Future queryData([bool isRefresh = true]) async {
|
||||
@@ -23,17 +27,19 @@ abstract class CommonController extends GetxController {
|
||||
isLoading = true;
|
||||
LoadingState response = await customGetData();
|
||||
if (response is Success) {
|
||||
if (!customHandleResponse(response)) {
|
||||
List currentList = loadingState.value is Success
|
||||
? (loadingState.value as Success).response
|
||||
: [];
|
||||
List? handleList = handleListResponse(currentList, response.response);
|
||||
loadingState.value = isRefresh
|
||||
? handleList != null
|
||||
? LoadingState.success(handleList)
|
||||
: response
|
||||
: LoadingState.success(currentList + response.response);
|
||||
handleSuccess(currentList, response.response);
|
||||
}
|
||||
currentPage++;
|
||||
List currentList = loadingState.value is Success
|
||||
? (loadingState.value as Success).response
|
||||
: [];
|
||||
List? handleList = handleResponse(currentList, response.response);
|
||||
loadingState.value = isRefresh
|
||||
? handleList != null
|
||||
? LoadingState.success(handleList)
|
||||
: response
|
||||
: LoadingState.success(currentList + response.response);
|
||||
handleSuccess(currentList, response.response);
|
||||
} else {
|
||||
if (isRefresh) {
|
||||
loadingState.value = response;
|
||||
@@ -55,6 +61,11 @@ abstract class CommonController extends GetxController {
|
||||
scrollController.animToTop();
|
||||
}
|
||||
|
||||
void onReload() {
|
||||
loadingState.value = LoadingState.loading();
|
||||
queryData();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
scrollController.dispose();
|
||||
|
||||
Reference in New Issue
Block a user