encodeQueryString function

String encodeQueryString(
  1. Map<String, String>? parameters
)

Encodes parameters as a query string.

Implementation

String encodeQueryString(Map<String, String>? parameters) {
  if (parameters == null || parameters.isEmpty) return '';

  var pairs = [];

  parameters.forEach((key, value) {
    var pair =
        '${Uri.encodeQueryComponent(key)}=${Uri.encodeQueryComponent(value)}';
    pairs.add(pair);
  });

  var queryString = pairs.join('&');
  return queryString;
}