SafeCallExtension extension
Extension on CLBaseViewModel that wraps a network call with the standard busy/error pattern used across the app.
- Toggles
setBusy(true/false)around the call. - Returns the value produced by
onSuccesswhen the response succeeded (HTTP 2xx), otherwisenull. - On non-2xx or thrown exceptions, optionally shows a danger alert via AlertManager.showDanger.
Usage:
final user = await safeCall<UserModel>(
call: () => ApiManager.instance.makeApiCall(...),
onSuccess: (data) => UserModel.fromJson(data),
errorTitle: 'Errore',
errorMessage: 'Impossibile caricare utente',
);
Methods
-
safeCall<
R> ({required Future< ApiCallResponse> call(), R onSuccess(dynamic data)?, String errorTitle = 'Errore', String? errorMessage, bool showErrorAlert = true, bool manageBusy = true}) → Future<R?> -
Available on CLBaseViewModel, provided by the SafeCallExtension extension
Wraps an ApiCallResponse-producing call with busy state and error handling.