-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for download
function in web
#2230
base: main
Are you sure you want to change the base?
Changes from 15 commits
c429be1
7147d04
6e5a96b
4dec223
3853fc9
7cf567f
0b1fbe6
77c63b8
7bc44a1
cf1c52d
1bbc7f9
9db2305
5917273
d029294
9f1f36e
4507ef2
a71f76f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:dio/dio.dart'; | ||
|
||
import 'adapter.dart'; | ||
|
@@ -25,9 +27,24 @@ class DioForBrowser with DioMixin implements Dio { | |
String lengthHeader = Headers.contentLengthHeader, | ||
Object? data, | ||
Options? options, | ||
}) { | ||
throw UnsupportedError( | ||
'The download method is not available in the Web environment.', | ||
}) async { | ||
final Response response = await fetch( | ||
RequestOptions( | ||
baseUrl: urlPath, | ||
data: data, | ||
method: 'GET', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why always There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
responseType: ResponseType.blobUrl, | ||
queryParameters: queryParameters, | ||
cancelToken: cancelToken, | ||
onReceiveProgress: onReceiveProgress, | ||
), | ||
); | ||
|
||
final completer = Completer<Response>(); | ||
|
||
// Set response in Completer | ||
completer.complete(response); | ||
|
||
return completer.future; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are unnecessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will the result be after downloaded? Could you demonstrate how it works?
EDIT: Please also add an example somewhere in our examples so everyone can run and see how it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added an example in
example_flutter_app
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test on the local web, make sure CORS is disabled.
and use local
dio
anddio_web_adapter
in example_flutter_app pubspec