Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4b3c599
Migrate image picker platform interface to cross_file
BeMacized Jun 21, 2021
c4c5de4
[image_picker] Implemented changes for cross_file migration
BeMacized Jun 21, 2021
44aa4c5
[image_picker] migrated web implementation to cross_file
BeMacized Jun 22, 2021
e39fa1f
Reverted changes to web implementation to move to separate PR
BeMacized Jun 23, 2021
f4fbd0c
[image_picker_for_web] Migration to cross_file
BeMacized Jun 23, 2021
2de19b4
Merge branch 'master' into issue/70886
BeMacized Jun 30, 2021
86f604b
Merge branch 'issue/70886' into issue/70886-impl-web
BeMacized Jun 30, 2021
7b39862
Merge branch 'issue/70886' into issue/70886-impl-android-ios
BeMacized Jun 30, 2021
68e2ef8
Re-added old methods and marked them as deprecated.
BeMacized Jun 30, 2021
d345b37
Merge branch 'issue/70886' into issue/70886-impl-web
BeMacized Jun 30, 2021
a0ab00e
Update to match platform interface changes
BeMacized Jun 30, 2021
875704e
Merge branch 'issue/70886' into issue/70886-impl-android-ios
BeMacized Jun 30, 2021
a987170
Format & annotate deprecated classes.
BeMacized Jun 30, 2021
6ab2bb0
Merge branch 'issue/70886' into issue/70886-impl-web
BeMacized Jun 30, 2021
5900446
Merge branch 'issue/70886' into issue/70886-impl-android-ios
BeMacized Jun 30, 2021
217949d
Updated to match platform interface changes
BeMacized Jun 30, 2021
3fa10b9
Updated pubspec and changelog.
BeMacized Jun 30, 2021
c1ff8b2
Merge branch 'issue/70886' into issue/70886-impl-web
BeMacized Jun 30, 2021
addfe99
Updated platform interface dependency version
BeMacized Jun 30, 2021
6d329e6
Merge branch 'issue/70886' into issue/70886-impl-android-ios
BeMacized Jun 30, 2021
aefff73
Updated changelog and pubspec version
BeMacized Jun 30, 2021
f5a4163
Updated pubspec version and changelog
BeMacized Jun 30, 2021
2c4cd91
Fix analysis issues for deprecations
BeMacized Jul 2, 2021
69969b2
Merge branch 'issue/70886' into issue/70886-impl-web
BeMacized Jul 2, 2021
129efcb
Merge branch 'issue/70886' into issue/70886-impl-android-ios
BeMacized Jul 2, 2021
29e0c40
Remove Deprecation tags so we don't break consumers of this package o…
ditman Jul 8, 2021
c74cebb
Merge branch 'master' into issue/70886
ditman Jul 8, 2021
0a082c8
Merge branch 'issue/70886' into issue/70886-impl-web
BeMacized Jul 8, 2021
043db42
Merge branch 'issue/70886' into issue/70886-impl-android-ios
BeMacized Jul 8, 2021
4615db1
Temporary platform interface reference dependency
BeMacized Jul 8, 2021
d3662f6
Merge branch 'issue/70886-impl-web' into issue/70886-impl-android-ios
BeMacized Jul 8, 2021
84ee0a2
Temporary dependency update
BeMacized Jul 8, 2021
faa1a99
Implement PR feedback
BeMacized Jul 8, 2021
afa61ab
Merge branch 'issue/70886' into issue/70886-impl-web
BeMacized Jul 8, 2021
b29ec7f
Merge branch 'issue/70886-impl-web' into issue/70886-impl-android-ios
BeMacized Jul 8, 2021
756633b
Update platform interface and web implementation dependency references
BeMacized Jul 13, 2021
c1131d5
Merge branch 'master' into issue/70886-impl-android-ios
BeMacized Jul 13, 2021
c7fd236
Update documentation
BeMacized Jul 13, 2021
8c89c99
Fix merge issues
BeMacized Jul 13, 2021
8073e7a
Fix merge issues
BeMacized Jul 13, 2021
bda48dd
Move tests of deprecated methods to new file, and ignore warnings the…
ditman Jul 14, 2021
a9534fe
Update Changelog to mention the deprecation of the current methods, a…
ditman Jul 14, 2021
e59bb03
Remove unnecessary ignore_for_file from plugin code.
ditman Jul 14, 2021
dc0e7eb
Merge branch 'master' into issue/70886-impl-android-ios
ditman Jul 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update documentation
  • Loading branch information
BeMacized committed Jul 13, 2021
commit c7fd236bdcf2d58926f0500539d9de0c63e740bb
86 changes: 25 additions & 61 deletions packages/image_picker/image_picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ First, add `image_picker` as a [dependency in your pubspec.yaml file](https://fl
### iOS

Starting with version **0.8.1** the iOS implementation uses PHPicker to pick (multiple) images on iOS 14 or higher.
As a result of implementing PHPicker it becomes impossible to pick HEIC images on the iOS simulator in iOS 14+. This is a known issue. Please test this on a real device, or test with non-HEIC images until Apple solves this issue.[63426347 - Apple known issue](https://www.google.com/search?q=63426347+apple&sxsrf=ALeKk01YnTMid5S0PYvhL8GbgXJ40ZS[…]t=gws-wiz&ved=0ahUKEwjKh8XH_5HwAhWL_rsIHUmHDN8Q4dUDCA8&uact=5)
As a result of implementing PHPicker it becomes impossible to pick HEIC images on the iOS simulator in iOS 14+. This is a known issue. Please test this on a real device, or test with non-HEIC images until Apple solves this issue.[63426347 - Apple known issue](https://www.google.com/search?q=63426347+apple&sxsrf=ALeKk01YnTMid5S0PYvhL8GbgXJ40ZS[…]t=gws-wiz&ved=0ahUKEwjKh8XH_5HwAhWL_rsIHUmHDN8Q4dUDCA8&uact=5)

Add the following keys to your _Info.plist_ file, located in `<project root>/ios/Runner/Info.plist`:

Expand All @@ -37,7 +37,19 @@ If you require your picked image to be stored permanently, it is your responsibi
import 'package:image_picker/image_picker.dart';

...
final PickedFile? pickedFile = await picker.getImage(source: ImageSource.camera);
final ImagePicker _picker = ImagePicker();
// Pick an image
final XFile? image = await _picker.pickImage(source: ImageSource.gallery);
// Capture a photo
final XFile? photo = await _picker.pickImage(source: ImageSource.camera);
// Pick a video
final XFile? image = await _picker.pickVideo(source: ImageSource.gallery);
// Capture a video
final XFile? photo = await _picker.pickVideo(source: ImageSource.camera);
// Pick multiple images
final List<XFile>? images = await _picker.pickMultiImage(source: ImageSource.gallery);
// Pick multiple photos
final List<XFile>? photos = await _picker.pickMultiImage(source: ImageSource.camera);
...
```

Expand All @@ -46,9 +58,9 @@ import 'package:image_picker/image_picker.dart';
Android system -- although very rarely -- sometimes kills the MainActivity after the image_picker finishes. When this happens, we lost the data selected from the image_picker. You can use `retrieveLostData` to retrieve the lost data in this situation. For example:

```dart
Future<void> retrieveLostData() async {
final LostData response =
await picker.getLostData();
Future<void> getLostData() async {
final LostDataResponse response =
await picker.retrieveLostData();
if (response.isEmpty) {
return;
}
Expand All @@ -57,7 +69,7 @@ Future<void> retrieveLostData() async {
if (response.type == RetrieveType.video) {
_handleVideo(response.file);
} else {
_handleImage(response.file);
_handleImage(response.file);
}
});
} else {
Expand All @@ -68,65 +80,17 @@ Future<void> retrieveLostData() async {

There's no way to detect when this happens, so calling this method at the right place is essential. We recommend to wire this into some kind of start up check. Please refer to the example app to see how we used it.

On Android, `getLostData` will only get the last picked image when picking multiple images, see: [#84634](https://github.com/flutter/flutter/issues/84634).
On Android, `retrieveLostData` will only get the last picked image when picking multiple images, see: [#84634](https://github.com/flutter/flutter/issues/84634).

## Deprecation warnings in `pickImage`, `pickVideo` and `LostDataResponse`
## Migrating to 0.8.2+

Starting with version **0.6.7** of the image_picker plugin, the API of the plugin changed slightly to allow for web implementations to exist.

The **old methods that returned `dart:io` File objects were marked as deprecated**, and a new set of methods that return [`PickedFile` objects](https://pub.dev/documentation/image_picker_platform_interface/latest/image_picker_platform_interface/PickedFile-class.html) were introduced.

### How to migrate from to ^0.6.7

#### Instantiate the `ImagePicker`

The new ImagePicker API does not rely in static methods anymore, so the first thing you'll need to do is to create a new instance of the plugin where you need it:

```dart
final _picker = ImagePicker();
```
Starting with version **0.8.2** of the image_picker plugin, new methods have been added for picking files that return `XFile` instances (from the [cross_file](https://pub.dev/packages/cross_file) package) rather than the plugin's own `PickedFile` instances. While the previous methods still exist, it is already recommended to start migrating over to their new equivalents. Eventually, `PickedFile` and the methods that return instances of it will be deprecated and removed.

#### Call the new methods

The new methods **receive the same parameters as before**, but they **return a `PickedFile`, instead of a `File`**. The `LostDataResponse` class has been replaced by the [`LostData` class](https://pub.dev/documentation/image_picker_platform_interface/latest/image_picker_platform_interface/LostData-class.html).

| Old API | New API |
|---------|---------|
| `File image = await ImagePicker.pickImage(...)` | `PickedFile image = await _picker.getImage(...)` |
| `File video = await ImagePicker.pickVideo(...)` | `PickedFile video = await _picker.getVideo(...)` |
| `LostDataResponse response = await ImagePicker.retrieveLostData()` | `LostData response = await _picker.getLostData()` |

#### `PickedFile` to `File`

If your app needs dart:io `File` objects to operate, you may transform `PickedFile` to `File` like so:

```dart
final pickedFile = await _picker.getImage(...);
final File file = File(pickedFile.path);
```

You may also retrieve the bytes from the pickedFile directly if needed:

```dart
final bytes = await pickedFile.readAsBytes();
```

#### Getting ready for the web platform

Note that on the web platform (`kIsWeb == true`), `File` is not available, so the `path` of the `PickedFile` will point to a network resource instead:

```dart
if (kIsWeb) {
image = Image.network(pickedFile.path);
} else {
image = Image.file(File(pickedFile.path));
}
```

Alternatively, the code may be unified at the expense of memory utilization:

```dart
image = Image.memory(await pickedFile.readAsBytes())
```

Take a look at the changes to the `example` app introduced in version 0.6.7 to see the migration steps applied there.
| `PickedFile image = await _picker.getImage(...)` | `XFile image = await _picker.pickImage(...)` |
| `List<PickedFile> images = await _picker.getMultiImage(...)` | `List<XFile> images = await _picker.pickMultiImage(...)` |
| `PickedFile video = await _picker.getVideo(...)` | `XFile video = await _picker.pickVideo(...)` |
| `LostData response = await _picker.getLostData()` | `LostDataResponse response = await _picker.retrieveLostData()` |