buildCanonicalQueryString static method

String buildCanonicalQueryString(
  1. Map<String, String>? queryParams
)

Implementation

static String buildCanonicalQueryString(Map<String, String>? queryParams) {
  if (queryParams == null) {
    return '';
  }

  final sortedQueryParams = [];
  queryParams.forEach((key, value) {
    sortedQueryParams.add(key);
  });
  sortedQueryParams.sort();

  final canonicalQueryStrings = [];
  for (var key in sortedQueryParams) {
    canonicalQueryStrings.add(
        '$key=${Uri.encodeQueryComponent(queryParams[key]!).replaceAll('+', "%20")}');
  }

  return canonicalQueryStrings.join('&');
}