Skip to content

Commit 278cadf

Browse files
committed
Added send progress to IOClient
1 parent 7c131a0 commit 278cadf

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/src/io_client.dart

+18-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,24 @@ class IOClient extends BaseClient {
4545
ioRequest.headers.set(name, value);
4646
});
4747

48-
var response = await stream.pipe(ioRequest) as HttpClientResponse;
48+
HttpClientResponse response;
49+
if (onSendProgress != null) {
50+
var loaded = 0;
51+
onSendProgress(loaded, request.contentLength);
52+
53+
await ioRequest.addStream(
54+
stream.map(
55+
(chunk) {
56+
loaded += chunk.length;
57+
onSendProgress(loaded, request.contentLength);
58+
return chunk;
59+
},
60+
),
61+
);
62+
response = await ioRequest.close();
63+
} else {
64+
response = await stream.pipe(ioRequest) as HttpClientResponse;
65+
}
4966

5067
var headers = <String, String>{};
5168
response.headers.forEach((key, values) {

0 commit comments

Comments
 (0)