buildCanonicalQueryString static method

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

Implementation

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

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

  final List<String> canonicalQueryStrings = [];
  for (var key in sortedQueryParams) {
    canonicalQueryStrings
        .add('$key=${Uri.encodeComponent(queryParams[key]!)}');
  }

  return canonicalQueryStrings.join('&');
}