encodeQuery static method
Encodes the given paramters into a query string.
- Notice the returned string won't start with
'?'
. - The value of a parameter will be converted to a string first.
- If it is null, an empty string is generated.
Implementation
static String encodeQuery(Map<String, dynamic> parameters) {
final buf = StringBuffer();
for (final name in parameters.keys) {
if (!buf.isEmpty)
buf.write('&');
buf..write(Uri.encodeQueryComponent(name))..write('=');
final value = parameters[name],
sval = value != null ? value.toString(): null;
if (sval?.isNotEmpty ?? false)
buf.write(Uri.encodeQueryComponent(sval!));
}
return buf.toString();
}