encodeQuery static method

String encodeQuery(
  1. Map<String, dynamic> parameters
)

Encodes the given parameters 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 or its string form is empty, only name= is
  • emitted (no value).

Implementation

static String encodeQuery(Map<String, dynamic> parameters) {
  final buf = StringBuffer();
  for (final entry in parameters.entries) {
    if (buf.isNotEmpty)
      buf.write('&');
    buf..write(Uri.encodeQueryComponent(entry.key))..write('=');
    final sval = entry.value?.toString();
    if (sval != null && sval.isNotEmpty)
      buf.write(Uri.encodeQueryComponent(sval));
  }
  return buf.toString();
}