How do I get query parameters in the URL

import 'dart:html';   

void doWork(){  
  var uri = Uri.dataFromString(window.location.href); //converts string to a uri    
  Map<String, String> params = uri.queryParameters; // query parameters automatically populated
  var param1 = params['param1']; // return value of parameter "param1" from uri
  var param2 = params['param2'];
  print(jsonEncode(params)); //can use returned parameters to encode as json
}

Import 'dart:html' then you can use window.location...


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

ie:

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
}

Tags:

Url

Dart