constructUrlWithQueryParams function

String constructUrlWithQueryParams(
  1. String url,
  2. Map<String, dynamic>? parameters
)

Construct full URL from base URL and query parameters object. @param url url without query parameters @param parameters query parameters

Implementation

String constructUrlWithQueryParams(
    String url, Map<String, dynamic>? parameters) {
  if (parameters == null) {
    return url;
  }
  final cleanParams = Map<String, dynamic>.from(parameters)
    ..removeWhere((key, value) => value == null || value == '');
  final queryParams = Uri(
      queryParameters: cleanParams
          .map((key, value) => MapEntry(key, value.toString()))).query;
  return queryParams.isNotEmpty ? '$url?$queryParams' : url;
}