getSellers method

Future<ApiCallback<List<Seller>>> getSellers(
  1. {String latitude,
  2. String longitude,
  3. String cartId}
)

Implementation

Future<ApiCallback<List<Seller>>> getSellers(
    {String latitude, String longitude, String cartId}) async {
  try {
    if (cartId == null) cartId = await _getDefaultCartId();

    Map<String, String> queryParameters = {};

    if (latitude != null && longitude != null) {
      queryParameters['lat'] = latitude;
      queryParameters['lng'] = longitude;
    } else {
      queryParameters['lat'] = '0.0';
      queryParameters['lng'] = '0.0';
    }

    var response = await _requester.get(
        GET_SELLERS.replaceAll(PARAMETER_CART_ID, cartId),
        queryParameters: queryParameters);
    // Parse result
    var responseData = response.data as List;
    var sellers = List<Seller>();
    for (var row in responseData) {
      sellers.add(Seller.fromJson(row));
    }
    // Callback invocation
    return ApiCallback<List<Seller>>(isSuccessful: true, resultData: sellers);
  } on DioError catch (e) {
    return ApiCallback<List<Seller>>().defaultErrorCallback(e);
  }
}