Search code examples
dartdart-html

Parsing a URI to extract query parameters, with Dart


I have a request in this form:

http://website/index.html?name=MyName&token=12345

Is there a way how to extract name and token from this url? There is always an option to iterate through all characters and save it that way, but I am looking for more elegant solution in Dart.


Solution

  • var uri = Uri.parse('http://website/index.html?name=MyName&token=12345');
    uri.queryParameters.forEach((k, v) {
       print('key: $k - value: $v');
    });
    

    key: name - value: MyName
    key: token - value: 12345