-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[image_picker_for_web] Introduce image_picker_for_web package #2802
Conversation
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
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.
Mostly LGTM although I would prefer to return an ImageProvider
rather than a PickedFile
. This way, the developer could just do Image(pickedImage)
whether you are on web or not.
See: https://api.flutter.dev/flutter/widgets/Image/Image.html
@hterkelsen I looked a little bit into this, and the issue I encountered was that only Images can be created that way; there's no concept of VideoProvider, AudioProvider, "AssetProvider" or FileProvider (AFAIK), so that solution would only cover a fraction of the use cases of the plugin (I didn't measure what's the actual breakdown of usage, it might be a large fraction of the use cases :P) PS: Now that web and desktop are coming, there's already feature requests of "let me pick any arbitrary file from my disk. In any case, I think that's a very good idea for an extra API method down the line; if you're only using the plugin for Images, we can add a "PickedImageProvider" class that lets you create Image widgets directly! (It'd still require dart:io vs dart:html implementations, but they'd be doable). Do you think we need an issue to track that task (P5/P6?), or wait until some user asks for something like that explicitly? |
Ah, that makes sense. I don't think we need to add it in that case |
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.
LGTM
Published to pub.dev: |
hi I am stuck in some issues regarding file validation, i.e. how can we check is user has uploaded only image extension file on web, because user can select option "All files" and upload any file on web.
like here for web if I console the Image I am getting - Image(image: NetworkImage("blob:http://0.0.0.0:55555/316c9cde-1333-4294-a72d-03e45d97f5f7", scale: 1), frameBuilder: null, loadingBuilder: null, alignment: center, this.excludeFromSemantics: false, filterQuality: low) So, blob:http://0.0.0.0:55555/316c9cde-1333-4294-a72d-03e45d97f5f7 does not contain any file extension info or meta data kind something ?? Please Help ... |
@parammittal162 the only reliable way of doing what you want is either doing it via server-side, or by looking at the bytes of the You would be in a similar situation if your user renames "file.txt" to "file.jpg" and tries to pick it. |
ok Thanks @ditman |
@andrea689 thanks for the help! |
We probably need to add a file |
@ditman thanks for all your work on this. I've been messing with 0.6.7+1 and converted my implementation. I switched to bytes so that it would work on both web and mobile.
Works fine on mobile. I'm assuming that I missed something, and tips would be appreciated. |
"No implementation found for method pickImage on channel plugins.flutter.io/image_picker" @m-j-g The
Once the plugin has been adopted by more people and we iron out whatever issues/features come up, we'll endorse it, so you just need to depend on a recent version of Thanks for giving this a shot! PS: check the README in the web version of the plugin, it has documentation about installation, browser support, etc... |
@ditman |
@m-j-g makes sense, almost every other plugin "hides" the web implementation so you don't have to worry about it. Note that every web plugin has (or should have) a similar README, with installation instructions and "quirks" of the web platform. |
It worked! Thanks! But now I need to know the file extension for videos, and I can't find any suitable package for this one. Any suggestion? Thank you! |
a way to know the filename or even the extension would be a big help for sure. image_picker_web does this but the problem is it doesn't provide a network path. For videos I can't find a way to play a video using Byte data or Html.File |
@ditman Can you please share the link of the source code of the Demo: |
@ditman I used method pickImage found that image not resizing and compressing follow maxWidth maxHeight and imageQuality. Please suggest me. Thank you |
@nonnyzcsrt resizing on the fly is not supported on web, for now. You might be able to load the image bytes in a canvas and then do the resizing, but this is not natively supported! |
If someone ever gets here before "image resizing functionality" is implemented in the package, you can use the following function to resize an image in the browser:
|
@postacik this is a cool example, why not add it to the plugin code itself? |
@ditman , I am not familiar with the flutter plugins structure. It would be great if someone else could add it to the plugin. |
The thing that I was thinking about is that the code above is only meant for. Would it be better to make a code that runs on any platform?? |
If this code is run on iOS or Android it resizes the selected image with the given size parameters and image quality. However on web the maxWidth, maxHeight and imageQuality parameters have no effect. The image is returned as is. If you add this code to the web platform implementation, it will be behaving just like the mobile platforms. @ditman , please correct me if I'm wrong. |
@jesusrp98 @postacik yes, I think the native picker is already able to resize images both on iOS and Android. This is a missing feature of Flutter web. Please @jesusrp98, remember to create a Flutter issue for [image_picker_for_web] that explains what you're going to do :) @postacik the code for picking images in web is here, in case you want to lend a hand to @jesusrp98 :) https://github.com/flutter/plugins/blob/master/packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart |
By the way, ImageSource.camera has no effect on desktop. It works only on mobile. WhatsApp web uses browser WebRTC functions to capture image from webcam. There's a flutter library called flutter_webrtc which has web support and can capture image from webcam. Maybe we can copy the web implementation from that library to support ImageSource.camera on desktop. But this feature would need to push a new screen to the navigator which will allow the user to capture an image and then edit the captured image which is similar to the native code. Would you prefer such a feature on web? 2021-01-16-13-45-35.mp4 |
We're soon going to work on the |
any news for provide |
@Joseph-Nathan no, there's a whole bunch of UX that needs to be built around the |
Description
This is a first version of an Image Picker plugin for web.
Since dart:io File is not available on the web, this only implements the new
PickedFile
methods from the platform interface.Instead of storing a "normal" path value on the file, however, it stores an "object URL" (see
createObjectUrl
) that the browser keeps track of. The PickedFiles in the web platform can be accessed through a network request (not a file operation).Demo
https://dit-picker-tests.web.app
Known issues
revokeObjectUrl
to free resources in the browser?taking pics on an iPhone: the aspect ratio is lost, and every pic seems to be rendered in "landscape"(Can't reproduce anymore)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?