parseQueryString function

Map<String, String> parseQueryString(
  1. String location
)

Parses a URL or query string into a single-value map of query parameters.

Keys and values are percent-decoded, + is converted to spaces, and duplicate keys follow "last-wins" semantics. Keys without values are assigned an empty string. If no query string is present, returns an empty map.

Safe for both server-side rendering (SSR) and browser environments.

final query = parseQueryString('/search?q=shoes+sale&category=footwear');
print(query['q']); // 'shoes sale'
print(query['category']); // 'footwear'

Implementation

Map<String, String> parseQueryString(String location) {
  final query = _extractQueryString(location);
  if (query.isEmpty) return const {};
  return Uri.splitQueryString(query);
}