removeQueryParam method

Uri removeQueryParam(
  1. String key
)

Returns a new Uri with key removed from the query string.

Uri.parse('https://example.com?page=1&q=dart').removeQueryParam('q')
// https://example.com?page=1

Implementation

Uri removeQueryParam(String key) {
  if (!queryParametersAll.containsKey(key)) return this;
  final params = Map<String, List<String>>.from(queryParametersAll)
    ..remove(key);
  if (params.isNotEmpty) return replace(queryParameters: params);
  // replace(query: null) keeps the original query; an empty string leaves '?'.
  return Uri(
    scheme: scheme,
    userInfo: userInfo,
    host: hasAuthority ? host : null,
    port: hasPort ? port : null,
    path: path,
    fragment: hasFragment ? fragment : null,
  );
}