putLocation method

Future<ApiCallback<void>> putLocation(
  1. {@required String latitude,
  2. @required String longitude,
  3. String cartId}
)

Implementation

Future<ApiCallback<void>> putLocation(
    {@required String latitude,
    @required String longitude,
    String cartId}) async {
  try {
    if (cartId == null) cartId = await _getDefaultCartId();

    var queryParameters = {
      'lat': latitude,
      'lng': longitude,
    };

    var response = await _requester.put(
        PUT_LOCATION.replaceAll(PARAMETER_CART_ID, cartId),
        queryParameters: queryParameters);
    // Parse the new cart
    var parsedCart = Cart.fromJson(response.data);
    // Save it locally
    await CartDao().insertOrUpdate(parsedCart);

    return ApiCallback<void>(isSuccessful: true);
  } on DioError catch (e) {
    return ApiCallback<void>().defaultErrorCallback(e);
  }
}