There’s not much to say about my problem.
The code is:
Future<bool> getThatUrl(cid) async { //cid = 0, for example
Map<String, dynamic> parameters = Map();
String email = '[email protected]';
parameters['email'] = email;
parameters['problematic_id'] = cid;
print(parameters); // prints: {email: [email protected], problematic_id: 0}
var uri = Uri.https('mywebpage.com', '/page.php', parameters);
print(uri); // prints:
}
The problem is, that uri
is (not generated? and) not printed, unless I remove parameters['problematic_id'] = 0
. If I remove it, then it prints https://mywebpage.com/page.php?email=anymail%40anymail.com
which is correct, but I need that problematic_id=0
there, too.
I tried using only one parameter, but if it’s parameters['problematic_id'] = 0
then it still doesn’t work.
2
Answers
This is actually an intended behavior.
I can see that at internal implementation, each
value
ofqueryParameters
should be either aIterable
or aString?
(String
ornull
) and you are passingint
(cid = 0) instead.Since
queryParameters
are in anyway treated asString
, you don’t have to worry about the type here. So, it’s better to just calltoString()
or convert yourcid
to string to solve this.Here’s a solution code:
Here line number 4, "$cid" will convert the cid to string hence solving the issue.
Hope this helps.
Edit:
(Thanks to @jamesdlin for the comment)
try converting the cid to a string explicitly before adding to parameters.