32

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.

Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
Vilda
  • 1,675
  • 1
  • 20
  • 50

1 Answers1

72
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
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Hi Günter Zöchbauer, can you suggest a solution for this -/http://1X.13X.X4.1XX:1000/report/DeleteFile?file=GA55-Estimated-NEHRU-LAL-2021-2022.pdf and i try to pass this fileNameGa = ga55estimated+"-NEHRU-LAL-" +year.toString() + "-" + year.toString() + ".pdf"; as query params getting this error og linked dynamic. – s.j Jun 10 '21 at 10:01
  • paasing this - final queryParameters = { 'file': fileNameGa, }; – s.j Jun 10 '21 at 10:02