buildUri function

Uri buildUri (
  1. String baseUrl,
  2. String url,
  3. Map<String, dynamic> parameters
)

Implementation

Uri buildUri(String baseUrl, String url, Map<String, dynamic> parameters) {
  var uri;
  if (url.startsWith('http://') || url.startsWith('https://')) {
    // if the request's url is already a fully qualified URL, we can use
    // as-is and ignore the baseUrl
    uri = Uri.parse(url);
  } else {
    if (!baseUrl.endsWith('/') && !url.startsWith('/')) {
      uri = Uri.parse('$baseUrl/$url');
    } else {
      uri = Uri.parse('$baseUrl$url');
    }
  }

  final query = mapToQuery(parameters);
  if (query.isNotEmpty) {
    return uri.replace(query: query);
  }
  return uri;
}