Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/api/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ class ApiConnection {
final int httpStatus = response.statusCode;
Map<String, dynamic>? json;
try {
final bytes = await response.stream.toBytes();
json = jsonUtf8Decoder.convert(bytes) as Map<String, dynamic>?;
// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would be helpful to add a comment on why we do this here.

json = await jsonStream.single as Map<String, dynamic>?;
} catch (e) {
// We'll throw something below, seeing `json` is null.
}
Expand Down