import '../utils/common_api_service.dart'; import '../utils/show_snackbar.dart'; class ProductService { Future>?> getProduct(int page, {String? category}) async { try { String url; if (category != null && category.isNotEmpty) { url = "/api/product/getAll/user?page=$page&category=$category"; } else { url = "/api/product/getAll/user?page=$page"; // URL without category filter } final response = await commonApiService>>( method: "GET", url: url, fromJson: (json) { if (json['products'] != null) { final List> products = (json['products'] as List) .map((productJson) => productJson as Map) .toList(); return products; } else { return []; } }, ); return response; } catch (e) { showSnackbar(e.toString()); //print("Error: $e"); } return null; } Future>?> getCategory() async { try { final response = await commonApiService>>( method: "GET", url: "/api/category/getCategories", fromJson: (json) { if (json['categories'] != null) { final List> category = (json['categories'] as List) .map((productJson) => productJson as Map) .toList(); return category; } else { return []; } }, ); return response; } catch (e) { showSnackbar(e.toString()); print("Error: $e"); } return null; } }