fetchCustomers method
Implementation
void fetchCustomers(BuildContext context) async {
tempAllCustomers.clear();
allCustomers.clear();
try {
isLoading(true);
var request = {
'api_key': await Constants.apiKey(),
'merchant_id' : Storage.getValue(Constants.merchantID)
};
var response = await DioClient().request(
context: context,
api: '/merchant/customers/get',
method: Method.POST,
params: request);
AllCustomersResponse customersResponse=
AllCustomersResponse.fromJson(response);
if (customersResponse.status == Strings.success) {
allCustomers.addAll(customersResponse.data!.obs);
tempAllCustomers.addAll(customersResponse.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().toTitleCase();
return Utils.showSnackbar(
context, Strings.error, e.toString().toTitleCase(), AppColors.red);
} finally {
isLoading(false);
}
update();
}