Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract parameter / value pairs from an Uri as a Map

Tags:

dart

How do I get the parameter / value pairs of an URL / URI using Dart? Unfortunately currently there is no built-in functionality for this problem neither in the Uri library or the Location interface.

like image 217
Alex Avatar asked Aug 02 '12 08:08

Alex


2 Answers

You can use Uri.splitQueryString to split the query into a map.

like image 103
Alexandre Ardhuin Avatar answered Oct 15 '22 22:10

Alexandre Ardhuin


There is now a queryParameters member of Uri that returns a Map

Uri u = Uri.parse("http://app.org/main?foo=bar&baz=bat");
Map<String,String> qp = u.queryParameters;
print(qp);

// {foo: bar, baz: bat}
like image 38
Mark E. Haase Avatar answered Oct 15 '22 21:10

Mark E. Haase