toQueryString property

String get toQueryString

Converts the map into a URL query-string style representation (e.g. ?key1=value1&key2=value2)

Example:

final url = 'https://www.example.com/search';
final map = {'name': 'Hussein Shakir', 'job': 'Flutter Developer'};
final urlWithQueryString = '$url${map.toQueryString()}';
print(urlWithQueryString); // Output: 'https://www.example.com/search?name=Hussein%20Shakir&job=Flutter%20Developer'

Implementation

String get toQueryString => entries
    .map((e) => '?${e.key}=${Uri.encodeComponent(e.value.toString())}')
    .join('&');