fetchOrders method
Implementation
Future<void> fetchOrders(BuildContext context, String? merchantID) async {
tempItems.clear();
items.clear();
try {
isLoading(true);
var request = {
'api_key': await Constants.apiKey(),
'merchant_id': merchantID ?? Storage.getValue(Constants.merchantID)
};
var response = await DioClient().request(
context: context,
api: '/merchant/orders/get',
method: Method.POST,
params: request);
AllOrdersResponse allOrdersResponse =
AllOrdersResponse.fromJson(response);
if (allOrdersResponse.status == Strings.success) {
tempItems.addAll(allOrdersResponse.data!.obs);
items.addAll(allOrdersResponse.data!.obs);
mainItemList.addAll(allOrdersResponse.data!.obs);
totalResults = items.length.obs;
} else {
isError(true);
errorMessage.value = response['message'].toString().toTitleCase();
return Utils.showSnackbar(context, Strings.error,
response['message'].toString().toTitleCase(), AppColors.red);
}
} finally {
isLoading(false);
}
update();
}