fetchMerchants method
Implementation
void fetchMerchants(BuildContext context) async {
tempAllMerchants.clear();
allMerchants.clear();
try {
isLoading(true);
var request = {
'api_key': await Constants.apiKey(),
};
var response = await DioClient().request(
context: context,
api: '/merchant/all',
method: Method.POST,
params: request);
AllMerchantsResponse merchantResponse =
AllMerchantsResponse.fromJson(response);
if (merchantResponse.status == Strings.success) {
allMerchants.addAll(merchantResponse.data!.obs);
tempAllMerchants.addAll(merchantResponse.data!.obs);
} else {
isError(true);
errorMessage.value = response['message'].toString().toTitleCase();
return Utils.showSnackbar(context, Strings.error,
response['message'].toString().toTitleCase(), AppColors.red);
}
} catch (e) {
isError(true);
errorMessage.value = e.toString().toString().toTitleCase();
return Utils.showSnackbar(
context, Strings.error, e.toString().toTitleCase(), AppColors.red);
} finally {
isLoading(false);
}
update();
}