-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[image_picker] 🚧 Add support for web 🚧 #2767
Conversation
This comment has been minimized.
This comment has been minimized.
(The Googlebot comment is not very relevant to this PR, since this is not what's going to be merged. This is the POC with all the changes required, that will be split into 3 PRs that need to be merged in order.) |
@ditman demo looks perfect. nice work! |
Currently writing tests for the image_picker_for_web package. |
@ditman also added a new method and updated the example: ditman#366 I added this so in the future it would be easy to add to return types and combinations. For example we could add "imageVideo" as a return type to support the gallery picking any file and furthermore we could add "file" for picking documents. This will greatly cut down on the boilerplate for the developer as more types are added. I think this will be important as the plugin moves to desktop too and the types of files can be vast. |
packages/image_picker/image_picker_for_web/android/src/main/AndroidManifest.xml
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/ios/image_picker_for_web.podspec
Show resolved
Hide resolved
import './base.dart'; | ||
|
||
/// A PickedFile backed by a dart:io File. | ||
class PickedFile extends PickedFileBase { |
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.
Why do we need 2 different PickedFile
s?
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.
Yes, we need them because only the appropriate one gets conditionally exported by the picked_file.dart file.
Borrowed from Rody Davis' file_access package. Co-authored-by: Rody Davis <rody.davis.jr@gmail.com>
This comment has been minimized.
This comment has been minimized.
Run with flutter test / flutter test --platform chrome
Hey @rodydavis, can you please hit #2791 with a message of consent towards the Googlebot? Thanks! |
Thanks guys, you're awesome ❤️ |
Sure thing 😎 and thanks @ditman for doing this PR! |
I check the demo on an iPhone -> OK |
@fvisticot correct; desktop browsers don't support the Once the |
The latest version of image_picker (that uses the new API, and enables the web version) has just been published: v0.6.7 It contains information on migrating from the old API to the new one, after the deprecation of |
Published the PR introducing the web version of the plugin here: #2802 |
Closing in favor of: #2802 |
can someone give an example of how to make a common code for mobile and web for image picker?? |
Hello, i'm interesting about this example too :)
but it's not work in web. I will waiting the new merge :) |
Description
This is a first pass at a version of the Image Picker plugin for web. There's a few changes:
PickedFile
. Thanks for the inspiration @rodydavis!PickedFile
s, and not "String" or dart:io "File".@Deprecate
old methods with references to the current ones.example
to use the new API.createObjectUrl
so we don't need to load bytes manually, the browser keeps a reference to the picked files for when we need them, and data from those files can be accessed through a "network" request.Demo
https://dit-picker-tests.web.app
Missing things / Known issues / Limitations
revokeObjectUrl
to free resources in the browser? This might be a memory leak in long-lived apps.Related Issues
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?
The change is breaking, but backwards compatible. Users will need to migrate their apps to a new (non static) API, and a new return value from the plugin.