refactor: reply

This commit is contained in:
bggRGjQaUbCoE
2024-09-08 16:14:57 +08:00
parent 2bcddc1097
commit bb6aaaa480
20 changed files with 640 additions and 935 deletions

View File

@@ -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();