This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[image_picker_for_web] Introduce image_picker_for_web package (#2802)
- Loading branch information
Showing
14 changed files
with
522 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 0.1.0 | ||
|
||
* Initial open-source release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following disclaimer | ||
// in the documentation and/or other materials provided with the | ||
// distribution. | ||
// * Neither the name of Google Inc. nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# image_picker_for_web | ||
|
||
A web implementation of [`image_picker`][1]. | ||
|
||
## Browser Support | ||
|
||
Since Web Browsers don't offer direct access to their users' file system, | ||
this plugin provides a `PickedFile` abstraction to make access access uniform | ||
across platforms. | ||
|
||
The web version of the plugin puts network-accessible URIs as the `path` | ||
in the returned `PickedFile`. | ||
|
||
### URL.createObjectURL() | ||
|
||
The `PickedFile` object in web is backed by [`URL.createObjectUrl` Web API](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL), | ||
which is reasonably well supported across all browsers: | ||
|
||
![Data on support for the bloburls feature across the major browsers from caniuse.com](https://caniuse.bitsofco.de/image/bloburls.png) | ||
|
||
However, the returned `path` attribute of the `PickedFile` points to a `network` resource, and not a | ||
local path in your users' drive. See **Use the plugin** below for some examples on how to use this | ||
return value in a cross-platform way. | ||
|
||
### input file "accept" | ||
|
||
In order to filter only video/image content, some browsers offer an [`accept` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept) in their `input type="file"` form elements: | ||
|
||
![Data on support for the input-file-accept feature across the major browsers from caniuse.com](https://caniuse.bitsofco.de/image/input-file-accept.png) | ||
|
||
This feature is just a convenience for users, **not validation**. | ||
|
||
Users can override this setting on their browsers. You must validate in your app (or server) | ||
that the user has picked the file type that you can handle. | ||
|
||
### input file "capture" | ||
|
||
In order to "take a photo", some mobile browsers offer a [`capture` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/capture): | ||
|
||
![Data on support for the html-media-capture feature across the major browsers from caniuse.com](https://caniuse.bitsofco.de/image/html-media-capture.png) | ||
|
||
Each browser may implement `capture` any way they please, so it may (or may not) make a | ||
difference in your users' experience. | ||
|
||
## Usage | ||
|
||
### Import the package | ||
|
||
This package is an unendorsed web platform implementation of `image_picker`. | ||
|
||
In order to use this, you'll need to depend in `image_picker: ^0.6.7` (which was the first version of the plugin that allowed federation), and `image_picker_for_web: ^0.1.0`. | ||
|
||
```yaml | ||
... | ||
dependencies: | ||
... | ||
image_picker: ^0.6.7 | ||
image_picker_for_web: ^0.1.0 | ||
... | ||
... | ||
``` | ||
|
||
### Use the plugin | ||
|
||
You should be able to use `package:image_picker` _almost_ as normal. | ||
|
||
Once the user has picked a file, the returned `PickedFile` instance will contain a | ||
`network`-accessible URL (pointing to a location within the browser). | ||
|
||
The instace will also let you retrieve the bytes of the selected file across all platforms. | ||
|
||
If you want to use the path directly, your code would need look like this: | ||
|
||
```dart | ||
... | ||
if (kIsWeb) { | ||
Image.network(pickedFile.path); | ||
} else { | ||
Image.file(File(pickedFile.path)); | ||
} | ||
... | ||
``` | ||
|
||
Or, using bytes: | ||
|
||
```dart | ||
... | ||
Image.memory(await pickedFile.readAsBytes()) | ||
... | ||
``` | ||
|
||
[1]: https://pub.dev/packages/image_picker |
8 changes: 8 additions & 0 deletions
8
packages/image_picker/image_picker_for_web/android/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
33 changes: 33 additions & 0 deletions
33
packages/image_picker/image_picker_for_web/android/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
group 'io.flutter.image_picker_for_web' | ||
version '1.0' | ||
|
||
buildscript { | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.5.0' | ||
} | ||
} | ||
|
||
rootProject.allprojects { | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
} | ||
lintOptions { | ||
disable 'InvalidPackage' | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/image_picker/image_picker_for_web/android/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
org.gradle.jvmargs=-Xmx1536M | ||
android.enableR8=true |
5 changes: 5 additions & 0 deletions
5
packages/image_picker/image_picker_for_web/android/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip |
1 change: 1 addition & 0 deletions
1
packages/image_picker/image_picker_for_web/android/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = 'image_picker_for_web' |
3 changes: 3 additions & 0 deletions
3
packages/image_picker/image_picker_for_web/android/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="io.flutter.image_picker_for_web"> | ||
</manifest> |
28 changes: 28 additions & 0 deletions
28
...r_for_web/android/src/main/java/io/flutter/image_picker_for_web/ImagePickerWebPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.image_picker_for_web; | ||
|
||
import io.flutter.embedding.engine.plugins.FlutterPlugin; | ||
import io.flutter.plugin.common.PluginRegistry.Registrar; | ||
|
||
/** ImagePickerWebPlugin */ | ||
public class ImagePickerWebPlugin implements FlutterPlugin { | ||
@Override | ||
public void onAttachedToEngine(FlutterPluginBinding flutterPluginBinding) {} | ||
|
||
// This static function is optional and equivalent to onAttachedToEngine. It supports the old | ||
// pre-Flutter-1.12 Android projects. You are encouraged to continue supporting | ||
// plugin registration via this function while apps migrate to use the new Android APIs | ||
// post-flutter-1.12 via https://flutter.dev/go/android-project-migration. | ||
// | ||
// It is encouraged to share logic between onAttachedToEngine and registerWith to keep | ||
// them functionally equivalent. Only one of onAttachedToEngine or registerWith will be called | ||
// depending on the user's project. onAttachedToEngine or registerWith must both be defined | ||
// in the same class. | ||
public static void registerWith(Registrar registrar) {} | ||
|
||
@Override | ||
public void onDetachedFromEngine(FlutterPluginBinding binding) {} | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/image_picker/image_picker_for_web/ios/image_picker_for_web.podspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html | ||
# | ||
Pod::Spec.new do |s| | ||
s.name = 'image_picker_for_web' | ||
s.version = '0.0.1' | ||
s.summary = 'No-op implementation of image_picker_for_web plugin to avoid build issues on iOS' | ||
s.description = <<-DESC | ||
temp fake image_picker_for_web plugin | ||
DESC | ||
s.homepage = 'https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker_for_web' | ||
s.license = { :file => '../LICENSE' } | ||
s.author = { 'Flutter Team' => 'flutter-dev@googlegroups.com' } | ||
s.source = { :path => '.' } | ||
s.source_files = 'Classes/**/*' | ||
s.public_header_files = 'Classes/**/*.h' | ||
s.dependency 'Flutter' | ||
|
||
s.ios.deployment_target = '8.0' | ||
end |
Oops, something went wrong.