getModalities method

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

Implementation

Future<ApiCallback<List<SellerModality>>> getModalities(
    {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_MODALITIES.replaceAll(PARAMETER_CART_ID, cartId),
        queryParameters: queryParameters);
    // Parse result
    var responseData = response.data as List;
    var modalities = List<SellerModality>();
    for (var row in responseData) {
      modalities.add(SellerModality.fromJson(row));
    }
    // Callback invocation
    return ApiCallback<List<SellerModality>>(
        isSuccessful: true, resultData: modalities);
  } on DioError catch (e) {
    return ApiCallback<List<SellerModality>>().defaultErrorCallback(e);
  }
}