decodeQuery static method

Map<String, String> decodeQuery(
  1. String queryString, {
  2. Map<String, String>? parameters,
})

Decodes the query string into a map of name-value pairs (aka., parameters). *

    • queryString - the query string shall not contain '?'.
    • parameters - the map to put the decoded parameters into.
  • If null, this method will instantiate a new map.

Implementation

static Map<String, String> decodeQuery(
    String queryString, {Map<String, String>? parameters}) {
  if (parameters == null)
    parameters = <String, String>{};

  int i = 0, len = queryString.length;
  while (i < len) {
    int j = i;
    int? iEquals;
    for (; j < len; ++j) {
      final cc = queryString.codeUnitAt(j);
      if (cc == $equal)
        iEquals = j;
      else if (cc == $amp || cc == $semicolon)
        break;
    }

    String name, value;
    if (iEquals != null) {
      name = queryString.substring(i, iEquals);
      value = queryString.substring(iEquals + 1, j);
    } else {
      name = queryString.substring(i, j);
      value = "";
    }
    i = j + 1;
    parameters[Uri.decodeQueryComponent(name)] = Uri.decodeQueryComponent(value);
  }
  return parameters;
}