withQueryParam method

Uri withQueryParam(
  1. String key,
  2. String value
)

Returns a new Uri with key=value added (or replaced) in the query.

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

Implementation

Uri withQueryParam(String key, String value) {
  final params = Map<String, String>.from(queryParameters);
  params[key] = value;
  return replace(queryParameters: params);
}