diff --git a/lib/api/core.dart b/lib/api/core.dart index 8d8c811e71..04671c40e3 100644 --- a/lib/api/core.dart +++ b/lib/api/core.dart @@ -147,8 +147,10 @@ class ApiConnection { final int httpStatus = response.statusCode; Map? json; try { - final bytes = await response.stream.toBytes(); - json = jsonUtf8Decoder.convert(bytes) as Map?; + // The stream-oriented `bind` method allows decoding to happen in chunks + // while the response is still being downloaded, improving latency. + final jsonStream = jsonUtf8Decoder.bind(response.stream); + json = await jsonStream.single as Map?; } catch (e) { // We'll throw something below, seeing `json` is null. }