fetchStoreCategory method

Future<List<String>> fetchStoreCategory(
  1. BuildContext context
)

Implementation

Future<List<String>> fetchStoreCategory(BuildContext context) async {
  try {
    isLoading(true);
    var request = {'api_key': await Constants.apiKey()};
    var response = await DioClient().request(
        context: context,
        api: '/merchant/categories',
        method: Method.POST,
        params: request);
    ProductCategoryResponse productCategoryResponse =
        ProductCategoryResponse.fromJson(response);
    if (productCategoryResponse.status == Strings.success) {
      storeCategoryList.addAll(productCategoryResponse.data!);
      storeCategory.value =
          storeCategoryList.isEmpty ? "" : storeCategoryList.first;
      update();
      return storeCategoryList;
    } else {
      Utils.showSnackbar(context, Strings.error,
          response['message'].toString().toTitleCase(), AppColors.red);
      return [];
    }
  } catch (e) {
    Utils.showSnackbar(
        context, Strings.error, e.toString().toTitleCase(), AppColors.red);
    return [];
  } finally {
    isLoading(false);
  }
}