buildQueryString function Null safety

String buildQueryString(
  1. Map<String, dynamic> params
)

Implementation

String buildQueryString(Map<String, dynamic> params) {
  final queryString = StringBuffer();

  if (params.isNotEmpty && !params.values.every((value) => value == null)) {
    queryString.write('?');
  }

  var i = 0;
  for (final key in params.keys) {
    i++;
    if (params[key] == null) {
      continue;
    }
    queryString.write('$key=${Uri.encodeComponent(params[key].toString())}');
    if (i != params.keys.length) {
      queryString.write('&');
    }
  }
  return queryString.toString();
}