Copybara Prod has uploaded this change for review.
expose onUploadProgress on HttpRequest dart:html
Context:
I am using HttpRequest in `dart:html` to upload file.
All is ok when I use HttpRequest with `onProgress` on Flutter `2.0.5` but when I upgraded Flutter `2.2.0`, the `onProgress` is not called then I read the document and know the way use [xhr.upload.onprogress](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/upload) to get the upload progress and it works.
Closes https://github.com/dart-lang/sdk/pull/46132
https://github.com/dart-lang/sdk/pull/46132
GitOrigin-RevId: 9d5fa97b14c26cea3a085317d1062d0c87cb5c5f
Change-Id: I15e45efc059a02670f57e5f7e31d580da85897d1
---
M sdk/lib/html/dart2js/html_dart2js.dart
M tests/lib/html/xhr_test.dart
M tests/lib_2/html/xhr_test.dart
3 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index 6ade06e..5f5c9e9 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -18134,14 +18134,17 @@
*
* See also: [authorization headers](http://en.wikipedia.org/wiki/Basic_access_authentication).
*/
- static Future<HttpRequest> request(String url,
- {String? method,
- bool? withCredentials,
- String? responseType,
- String? mimeType,
- Map<String, String>? requestHeaders,
- sendData,
- void onProgress(ProgressEvent e)?}) {
+ static Future<HttpRequest> request(
+ String url, {
+ String? method,
+ bool? withCredentials,
+ String? responseType,
+ String? mimeType,
+ Map<String, String>? requestHeaders,
+ sendData,
+ void onProgress(ProgressEvent e)?,
+ void onUploadProgress(ProgressEvent e)?,
+ }) {
var completer = new Completer<HttpRequest>();
var xhr = new HttpRequest();
@@ -18172,6 +18175,10 @@
xhr.onProgress.listen(onProgress);
}
+ if (onUploadProgress != null) {
+ xhr.upload.onProgress.listen(onUploadProgress);
+ }
+
xhr.onLoad.listen((e) {
var status = xhr.status!;
var accepted = status >= 200 && status < 300;
diff --git a/tests/lib/html/xhr_test.dart b/tests/lib/html/xhr_test.dart
index bffd1cf..16c03be 100644
--- a/tests/lib/html/xhr_test.dart
+++ b/tests/lib/html/xhr_test.dart
@@ -99,6 +99,16 @@
validate200Response(xhr);
}
+Future testRequestOnUploadProgress() async {
+ var progressCalled = false;
+ var xhr = await HttpRequest.request(url, onUploadProgress: (_) {
+ progressCalled = true;
+ });
+ expect(xhr.readyState, HttpRequest.DONE);
+ expect(progressCalled, HttpRequest.supportsProgressEvent);
+ validate200Response(xhr);
+}
+
Future testRequestWithCredentialsNoFile() async {
try {
await HttpRequest.request('NonExistingFile', withCredentials: true);
diff --git a/tests/lib_2/html/xhr_test.dart b/tests/lib_2/html/xhr_test.dart
index 84fc4a6..d76a54b 100644
--- a/tests/lib_2/html/xhr_test.dart
+++ b/tests/lib_2/html/xhr_test.dart
@@ -101,6 +101,16 @@
validate200Response(xhr);
}
+Future testRequestOnUploadProgress() async {
+ var progressCalled = false;
+ var xhr = await HttpRequest.request(url, onUploadProgress: (_) {
+ progressCalled = true;
+ });
+ expect(xhr.readyState, HttpRequest.DONE);
+ expect(progressCalled, HttpRequest.supportsProgressEvent);
+ validate200Response(xhr);
+}
+
Future testRequestWithCredentialsNoFile() async {
try {
await HttpRequest.request('NonExistingFile', withCredentials: true);
To view, visit change 201280. To unsubscribe, or for help writing mail filters, visit settings.
Copybara Prod uploaded patch set #2 to this change.
expose onUploadProgress on HttpRequest dart:html
Context:
I am using HttpRequest in `dart:html` to upload file.
All is ok when I use HttpRequest with `onProgress` on Flutter `2.0.5` but when I upgraded Flutter `2.2.0`, the `onProgress` is not called then I read the document and know the way use [xhr.upload.onprogress](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/upload) to get the upload progress and it works.
Closes https://github.com/dart-lang/sdk/pull/46132
https://github.com/dart-lang/sdk/pull/46132
GitOrigin-RevId: 4512b166733aae2e00cf6257af282b8c6e70f2e3
Change-Id: I15e45efc059a02670f57e5f7e31d580da85897d1
---
M sdk/lib/html/dart2js/html_dart2js.dart
M tests/lib/html/xhr_test.dart
M tests/lib_2/html/xhr_test.dart
3 files changed, 35 insertions(+), 8 deletions(-)
To view, visit change 201280. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Srujan Gaddam.
Michael Thomsen would like Srujan Gaddam to review this change authored by Copybara Prod.
expose onUploadProgress on HttpRequest dart:html
Context:
I am using HttpRequest in `dart:html` to upload file.
All is ok when I use HttpRequest with `onProgress` on Flutter `2.0.5` but when I upgraded Flutter `2.2.0`, the `onProgress` is not called then I read the document and know the way use [xhr.upload.onprogress](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/upload) to get the upload progress and it works.
Closes https://github.com/dart-lang/sdk/pull/46132
https://github.com/dart-lang/sdk/pull/46132
GitOrigin-RevId: 4512b166733aae2e00cf6257af282b8c6e70f2e3
Change-Id: I15e45efc059a02670f57e5f7e31d580da85897d1
---
M sdk/lib/html/dart2js/html_dart2js.dart
M tests/lib/html/xhr_test.dart
M tests/lib_2/html/xhr_test.dart
3 files changed, 35 insertions(+), 8 deletions(-)
To view, visit change 201280. To unsubscribe, or for help writing mail filters, visit settings.
1 comment:
Patchset:
I believe that this still requires some changes to the template files that are being worked on, so will review when ready.
To view, visit change 201280. To unsubscribe, or for help writing mail filters, visit settings.