parseQueryString method

Map<String, List<String>> parseQueryString (
  1. String query
)

Implementation

Map<String, List<String>> parseQueryString(String query) {
  var search = RegExp('([^&=]+)=?([^&]*)');
  var params = Map<String, List<String>>();
  if (query.startsWith('?')) query = query.substring(1);
  decode(String s) => Uri.decodeComponent(s.replaceAll('+', ' '));
  for (Match match in search.allMatches(query)) {
    String key = decode(match.group(1));
    String value = decode(match.group(2));
    if (params.containsKey(key)) {
      params[key].add(value);
    } else {
      params[key] = [value];
    }
  }
  return params;
}