sendApiAction method
Future
sendApiAction(
- BuildContext context, {
- dynamic hud,
- OnData? onData,
- OnError? onError,
- OnHeaders? onHeaders,
Implementation
Future<dynamic> sendApiAction(BuildContext context,
{hud, OnData? onData, OnError? onError, OnHeaders? onHeaders}) async {
if (_viewModel != null) {
_viewModel?.start();
}
if (hud != null) {
FastHudView.show(context, msg: hud);
}
var result = await api(this.url(), this.doPost(), this.retJson(), onHeaders,
this, this.cacheTime());
if (hud != null) {
FastHudView.dismiss();
}
if (_viewModel != null) {
_viewModel?.finish();
}
if (result is String && result.contains('::')) {
List data = result.toString().split('::');
if (data.length == 3) {
if (onError != null) {
onError(data[1], int.parse(data[0].toString()));
}
throw FastResponseModel.fromError(
data[1], int.parse(data[0].toString()));
}
if (data.length == 4) {
if (onError != null) {
onError(data[1], int.parse(data[0].toString()));
}
throw FastResponseModel.fromError(data[1],
int.parse(data[0].toString()), jsonDecode(data[3] ?? '{}'));
}
}
return result;
}