Skip to content

Commit 9247301

Browse files
committed
Added send progress to IOClient
1 parent f7278d9 commit 9247301

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/src/io_client.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,24 @@ class IOClient extends BaseClient {
4040
ioRequest.headers.set(name, value);
4141
});
4242

43-
var response = await stream.pipe(ioRequest) as HttpClientResponse;
43+
HttpClientResponse response;
44+
if (onSendProgress != null) {
45+
var loaded = 0;
46+
onSendProgress(loaded, request.contentLength);
47+
48+
await ioRequest.addStream(
49+
stream.map(
50+
(chunk) {
51+
loaded += chunk.length;
52+
onSendProgress(loaded, request.contentLength);
53+
return chunk;
54+
},
55+
),
56+
);
57+
response = await ioRequest.close();
58+
} else {
59+
response = await stream.pipe(ioRequest) as HttpClientResponse;
60+
}
4461

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

0 commit comments

Comments
 (0)