diff --git a/pkgs/http/lib/src/utils.dart b/pkgs/http/lib/src/utils.dart index e79108e88a..91e8cd5429 100644 --- a/pkgs/http/lib/src/utils.dart +++ b/pkgs/http/lib/src/utils.dart @@ -12,14 +12,11 @@ import 'byte_stream.dart'; /// /// mapToQuery({"foo": "bar", "baz": "bang"}); /// //=> "foo=bar&baz=bang" -String mapToQuery(Map map, {Encoding? encoding}) { - var pairs = >[]; - map.forEach((key, value) => pairs.add([ - Uri.encodeQueryComponent(key, encoding: encoding ?? utf8), - Uri.encodeQueryComponent(value, encoding: encoding ?? utf8) - ])); - return pairs.map((pair) => '${pair[0]}=${pair[1]}').join('&'); -} +String mapToQuery(Map map, {Encoding encoding = utf8}) => + map.entries + .map((e) => '${Uri.encodeQueryComponent(e.key, encoding: encoding)}' + '=${Uri.encodeQueryComponent(e.value, encoding: encoding)}') + .join('&'); /// Returns the [Encoding] that corresponds to [charset]. /// @@ -34,8 +31,6 @@ Encoding encodingForCharset(String? charset, [Encoding fallback = latin1]) { /// /// Throws a [FormatException] if no [Encoding] was found that corresponds to /// [charset]. -/// -/// [charset] may not be null. Encoding requiredEncodingForCharset(String charset) => Encoding.getByName(charset) ?? (throw FormatException('Unsupported encoding "$charset".')); @@ -53,9 +48,8 @@ bool isPlainAscii(String string) => _asciiOnly.hasMatch(string); /// If [input] is a [TypedData], this just returns a view on [input]. Uint8List toUint8List(List input) { if (input is Uint8List) return input; - if (input is TypedData) { - // TODO(nweiz): remove "as" when issue 11080 is fixed. - return Uint8List.view((input as TypedData).buffer); + if (input case TypedData data) { + return Uint8List.view(data.buffer); } return Uint8List.fromList(input); }