How to get request parameters in url

In Dart, I am working on a web game. In this I need a function where I can get data from a URL, just as you would get it in PHP. How should I do it?

Say, for example, when I boot my web game, add the following to my the URL-address: ?id=15&randomNumber=3.14. How can I get them in Dart either as a source string (preferred) or in a different format?

+4
source share
2 answers

You can use the Uri class from dart: core
https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-core.Uri

t

main() {
  print(Uri.base.toString()); // http://localhost:8082/game.html?id=15&randomNumber=3.14
  print(Uri.base.query);  // id=15&randomNumber=3.14
  print(Uri.base.queryParameters['randomNumber']); // 3.14
}
+14
source

Import 'dart:html', then you can usewindow.location...

+3
source

All Articles