load method
Starts loading or refreshing the data managed by this service.
Sets the service status to ServiceStatus.loading or ServiceStatus.refresh
depending on the isRefresh flag. The actual data fetching is performed
by fetchData. This method must call either done on success or fail
on failure to properly update the service state and notify listeners.
Implementation
@mustCallSuper
Future<void> load({bool isRefresh = false}) async {
_status = isRefresh ? ServiceStatus.refresh : ServiceStatus.loading;
try {
done(await fetchData());
} catch (error) {
fail(error);
// Controls error handling: rethrows if [canRethrow], otherwise logs the failure.
if (canRethrow) {
rethrow;
} else if (canDebugPrint) {
debugPrint("Service $this failed to load: $error");
}
}
}