removeQueryParams static method

String removeQueryParams(
  1. String url,
  2. List<String> keys
)

Removes query parameters from a URL

Example:

UrlUtils.removeQueryParams('https://example.com?key=value', ['key']);
// 'https://example.com'

Implementation

static String removeQueryParams(String url, List<String> keys) {
  final uri = Uri.parse(url);
  final newParams = Map<String, String>.from(uri.queryParameters);
  for (final key in keys) {
    newParams.remove(key);
  }
  final newUri = uri.replace(queryParameters: newParams);
  return newUri.toString();
}