onLoadPageRest method
Implementation
Future<PageLoadedState> onLoadPageRest(LoadPageActionEvent event) async {
final props = event.action.props;
final isPaged = parseBool(props["isPaged"], defaultValue: true);
if (isPaged) {
final queryArgs = props["queryArgs"] ?? {};
queryArgs["page"] = event.page;
queryArgs["pageSize"] = event.pageSize;
props["queryArgs"] = queryArgs;
}
final result = await onRest(event.action, event.context);
if (result.success) {
var responseData = result.returnData;
if (responseData is Map) {
if (props["arrayKey"] != null) {
responseData = responseData[props["arrayKey"]];
} else {
for (var key in responseData.keys) {
if (responseData[key] is List) {
responseData = responseData[key];
break;
}
}
}
}
if (responseData is List) {
event.fullData.addAll(responseData);
return PageLoadedState(event.page, event.fullData,
isPaged && responseData.length == event.pageSize);
}
}
return PageLoadedState(event.page, event.fullData, false);
}