You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/services/pharmacy_services/wishList_service.dart

69 lines
2.6 KiB
Dart

import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';
import 'package:diplomaticquarterapp/models/pharmacy/Wishlist.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
class WishListService extends BaseService {
AppSharedPreferences sharedPref = AppSharedPreferences();
bool isLogin = false;
List<Wishlist> _wishListProducts = List();
List<Wishlist> get wishListProducts => _wishListProducts;
// Future<Map> getWishlist() async {
// var isLogin = await sharedPref.getString(LOGIN_TOKEN_ID);
// this.isLogin = isLogin != null;
//// if (!isLogin) {
//// // if not login
//// } else {
//// try {
//// await baseAppClient.get(
//// GET_WISHLIST +'/productsbyids/5308,3608,2316,963,5045,2714,1480,',//+ "272843" + "?shopping_cart_type=2",
//// onSuccess: (dynamic response, int statusCode) {
//// wishListProducts.clear();
//// response['shopping_carts'].forEach((item) {
//// wishListProducts.add(Product.fromJson(item));
//// });
//// }, onFailure: (String error, int statusCode) {
//// hasError = true;
//// super.error = error;
//// });
//// } catch (error) {
//// throw error;
//// }
//// }
// hasError = false;
// try {
// await baseAppClient.getPharmacy(GET_WISHLIST+"1367368?shopping_cart_type=2",
// onSuccess: (dynamic response, int statusCode) {
// wishListProducts.clear();
// response.forEach((item) {
// wishListProducts.add(Wishlist.fromJson(response));
// });
// }, onFailure: (String error, int statusCode) {
// hasError = true;
// super.error = error;
// });
// } catch (error) {
// throw error;
// }
// }
Future getWishlist() async {
//TODO we need to check why the customer id comes null
String customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID) ?? "0";
var customerGUID = await sharedPref.getObject(PHARMACY_CUSTOMER_GUID);
hasError = false;
await baseAppClient.getPharmacy(GET_WISHLIST + customerId + "/$customerGUID/" + "?shopping_cart_type=2", onSuccess: (dynamic response, int statusCode) {
_wishListProducts.clear();
response['shopping_carts'].forEach((item) {
_wishListProducts.add(Wishlist.fromJson(item));
});
}, onFailure: (String error, int statusCode) {
hasError = true;
super.error = error;
});
}
}