clearWishlist method

void clearWishlist(
  1. ClearWishlist clearWishlist
)

Implementation

void clearWishlist(ClearWishlist clearWishlist) async {
  clearWishlist.onLoading();

  final url = "https://api.plentrasphere.com/v2/client/index.php";
  final body = {
    'class': 'wishlist',
    "appKey": appKey,
    "action": "clearWishlist",
  };

  try {
    final response = await http.post(
      Uri.parse(url),
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
        'Authorization': 'Bearer $token'
      },
      body: body,
    );

    final data = json.decode(response.body);
    int code = data['response']['code'];
    String status = data['response']['status'];

    if (code == 400) {
      if (status == "session-expired" || status == "please-login") {
        clearWishlist.onNotLoggedIn();
        clearWishlist.onLoadfinished();
        return;
      }

      if (status == "app-expired") {
        clearWishlist.onAppNotActive(data['info']['appName']);
        clearWishlist.onLoadfinished();
        return;
      }

      clearWishlist.onError(status);
      clearWishlist.onLoadfinished();
      return;
    }

    clearWishlist.onSuccess(status);
    clearWishlist.onLoadfinished();
  } catch (e) {
    clearWishlist.onError(e.toString());
    clearWishlist.onLoadfinished();
  }
}