The following uri created:
final _url = "https://example.com/api/";
final _uri = Uri(path: _url, queryParameters: _params);
Results in http%3A//example.com/api/+{params...}
I have tried escaping by \:
and other methods but no luck :/
This problem only happens when run through Uri, I was unable to find any resources online to resolve this issue.
Your intention is
final String _url = "https://example.com/api/";
final Uri _uri = Uri
.parse(_url) // parse string
.replace(queryParameters: _params); // set params (no need manual escape, Uri do it itself)
So the best way to create an URI in Dart from a url string is using the Uri
dart package with its static methods http
or https
So you have to change your code as the following:
final _authority = "example.com";
final _path = "/api";
final _params = { "q" : "dart" };
final _uri = Uri.https(_authority, _path, _params);
Replace:
final _url = "https://example.com/api/";
final _uri = Uri(path: _url, queryParameters: _params);
with:
final _url = "example.com/api/";
final _uri = Uri.https(path: _url, queryParameters: _params);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With