decodeQueryString function

Map<String, String> decodeQueryString(
  1. String? queryString
)

Decodes queryString to a Map<String,String>.

Implementation

Map<String, String> decodeQueryString(String? queryString) {
  if (queryString == null || queryString.isEmpty) return {};

  var pairs = queryString.split('&');

  var parameters = <String, String>{};

  for (var pair in pairs) {
    if (pair.isEmpty) continue;
    var kv = pair.split('=');

    var k = kv[0];
    var v = kv.length > 1 ? kv[1] : '';

    k = Uri.decodeQueryComponent(k);
    v = Uri.decodeQueryComponent(v);

    parameters[k] = v;
  }

  return parameters;
}