Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
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
Updated to match platform interface changes
  • Loading branch information
BeMacized committed Jun 30, 2021
commit 217949d98a93bc97e912c22c1f9d5c7406c63dac
12 changes: 6 additions & 6 deletions packages/image_picker/image_picker/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {
List<PickedFile>? _imageFileList;
List<XFile>? _imageFileList;

set _imageFile(PickedFile? value) {
set _imageFile(XFile? value) {
_imageFileList = value == null ? null : [value];
}

Expand Down Expand Up @@ -84,14 +84,14 @@ class _MyHomePageState extends State<MyHomePage> {
await _controller!.setVolume(0.0);
}
if (isVideo) {
final XFile? file = await _picker.getVideo(
final XFile? file = await _picker.pickVideo(
source: source, maxDuration: const Duration(seconds: 10));
await _playVideo(file);
} else if (isMultiImage) {
await _displayPickImageDialog(context!,
(double? maxWidth, double? maxHeight, int? quality) async {
try {
final pickedFileList = await _picker.getMultiImage(
final pickedFileList = await _picker.pickMultiImage(
maxWidth: maxWidth,
maxHeight: maxHeight,
imageQuality: quality,
Expand All @@ -109,7 +109,7 @@ class _MyHomePageState extends State<MyHomePage> {
await _displayPickImageDialog(context!,
(double? maxWidth, double? maxHeight, int? quality) async {
try {
final pickedFile = await _picker.getImage(
final pickedFile = await _picker.pickImage(
source: source,
maxWidth: maxWidth,
maxHeight: maxHeight,
Expand Down Expand Up @@ -214,7 +214,7 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<void> retrieveLostData() async {
final LostData response = await _picker.getLostData();
final LostDataResponse response = await _picker.retrieveLostData();
if (response.isEmpty) {
return;
}
Expand Down
152 changes: 148 additions & 4 deletions packages/image_picker/image_picker/lib/image_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export 'package:image_picker_platform_interface/image_picker_platform_interface.
ImageSource,
CameraDevice,
LostData,
LostDataResponse,
PickedFile,
XFile,
RetrieveType;

Expand All @@ -25,9 +27,9 @@ class ImagePicker {
@visibleForTesting
static ImagePickerPlatform get platform => ImagePickerPlatform.instance;

/// Returns a [XFile] object wrapping the image that was picked.
/// Returns a [PickedFile] object wrapping the image that was picked.
///
/// The returned [XFile] is intended to be used within a single APP session. Do not save the file path and use it across sessions.
/// The returned [PickedFile] is intended to be used within a single APP session. Do not save the file path and use it across sessions.
///
/// The `source` argument controls where the image comes from. This can
/// be either [ImageSource.camera] or [ImageSource.gallery].
Expand Down Expand Up @@ -59,6 +61,7 @@ class ImagePicker {
/// the camera or photos gallery, no camera is available, plugin is already in use,
/// temporary file could not be created (iOS only), plugin activity could not
/// be allocated (Android only) or due to an unknown error.
@Deprecated('Switch to using pickImage instead')
Future<PickedFile?> getImage({
required ImageSource source,
double? maxWidth,
Expand Down Expand Up @@ -99,6 +102,7 @@ class ImagePicker {
/// be allocated (Android only) or due to an unknown error.
///
/// See also [getImage] to allow users to only pick a single image.
@Deprecated('Switch to using pickMultiImage instead')
Future<List<PickedFile>?> getMultiImage({
double? maxWidth,
double? maxHeight,
Expand All @@ -113,7 +117,7 @@ class ImagePicker {

/// Returns a [PickedFile] object wrapping the video that was picked.
///
/// The returned [XFile] is intended to be used within a single APP session. Do not save the file path and use it across sessions.
/// The returned [PickedFile] is intended to be used within a single APP session. Do not save the file path and use it across sessions.
///
/// The [source] argument controls where the video comes from. This can
/// be either [ImageSource.camera] or [ImageSource.gallery].
Expand All @@ -133,6 +137,7 @@ class ImagePicker {
/// temporary file could not be created and video could not be cached (iOS only),
/// plugin activity could not be allocated (Android only) or due to an unknown error.
///
@Deprecated('Switch to using pickVideo instead')
Future<PickedFile?> getVideo({
required ImageSource source,
CameraDevice preferredCameraDevice = CameraDevice.rear,
Expand All @@ -145,7 +150,7 @@ class ImagePicker {
);
}

/// Retrieve the lost [XFile] when [selectImage] or [selectVideo] failed because the MainActivity is destroyed. (Android only)
/// Retrieve the lost [PickedFile] when [selectImage] or [selectVideo] failed because the MainActivity is destroyed. (Android only)
///
/// Image or video can be lost if the MainActivity is destroyed. And there is no guarantee that the MainActivity is always alive.
/// Call this method to retrieve the lost data and process the data according to your APP's business logic.
Expand All @@ -158,7 +163,146 @@ class ImagePicker {
/// See also:
/// * [LostData], for what's included in the response.
/// * [Android Activity Lifecycle](https://developer.android.com/reference/android/app/Activity.html), for more information on MainActivity destruction.
@Deprecated('Switch to using retrieveLostData instead')
Future<LostData> getLostData() {
return platform.retrieveLostData();
}

/// Returns an [XFile] object wrapping the image that was picked.
///
/// The returned [XFile] is intended to be used within a single APP session. Do not save the file path and use it across sessions.
///
/// The `source` argument controls where the image comes from. This can
/// be either [ImageSource.camera] or [ImageSource.gallery].
///
/// Where iOS supports HEIC images, Android 8 and below doesn't. Android 9 and above only support HEIC images if used
/// in addition to a size modification, of which the usage is explained below.
///
/// If specified, the image will be at most `maxWidth` wide and
/// `maxHeight` tall. Otherwise the image will be returned at it's
/// original width and height.
/// The `imageQuality` argument modifies the quality of the image, ranging from 0-100
/// where 100 is the original/max quality. If `imageQuality` is null, the image with
/// the original quality will be returned. Compression is only supported for certain
/// image types such as JPEG and on Android PNG and WebP, too. If compression is not supported for the image that is picked,
/// a warning message will be logged.
///
/// Use `preferredCameraDevice` to specify the camera to use when the `source` is [ImageSource.camera].
/// The `preferredCameraDevice` is ignored when `source` is [ImageSource.gallery]. It is also ignored if the chosen camera is not supported on the device.
/// Defaults to [CameraDevice.rear]. Note that Android has no documented parameter for an intent to specify if
/// the front or rear camera should be opened, this function is not guaranteed
/// to work on an Android device.
///
/// In Android, the MainActivity can be destroyed for various reasons. If that happens, the result will be lost
/// in this call. You can then call [retrieveLostData] when your app relaunches to retrieve the lost data.
///
/// See also [pickMultiImage] to allow users to select multiple images at once.
///
/// The method could throw [PlatformException] if the app does not have permission to access
/// the camera or photos gallery, no camera is available, plugin is already in use,
/// temporary file could not be created (iOS only), plugin activity could not
/// be allocated (Android only) or due to an unknown error.
Future<XFile?> pickImage({
required ImageSource source,
double? maxWidth,
double? maxHeight,
int? imageQuality,
CameraDevice preferredCameraDevice = CameraDevice.rear,
}) {
return platform.getImage(
source: source,
maxWidth: maxWidth,
maxHeight: maxHeight,
imageQuality: imageQuality,
preferredCameraDevice: preferredCameraDevice,
);
}

/// Returns a [List<XFile>] object wrapping the images that were picked.
///
/// The returned [List<XFile>] is intended to be used within a single APP session. Do not save the file path and use it across sessions.
///
/// Where iOS supports HEIC images, Android 8 and below doesn't. Android 9 and above only support HEIC images if used
/// in addition to a size modification, of which the usage is explained below.
///
/// This method is not supported in iOS versions lower than 14.
///
/// If specified, the images will be at most `maxWidth` wide and
/// `maxHeight` tall. Otherwise the images will be returned at it's
/// original width and height.
/// The `imageQuality` argument modifies the quality of the images, ranging from 0-100
/// where 100 is the original/max quality. If `imageQuality` is null, the images with
/// the original quality will be returned. Compression is only supported for certain
/// image types such as JPEG and on Android PNG and WebP, too. If compression is not supported for the image that is picked,
/// a warning message will be logged.
///
/// The method could throw [PlatformException] if the app does not have permission to access
/// the camera or photos gallery, no camera is available, plugin is already in use,
/// temporary file could not be created (iOS only), plugin activity could not
/// be allocated (Android only) or due to an unknown error.
///
/// See also [pickImage] to allow users to only pick a single image.
Future<List<XFile>?> pickMultiImage({
double? maxWidth,
double? maxHeight,
int? imageQuality,
}) {
return platform.getMultiImage(
maxWidth: maxWidth,
maxHeight: maxHeight,
imageQuality: imageQuality,
);
}

/// Returns an [XFile] object wrapping the video that was picked.
///
/// The returned [XFile] is intended to be used within a single APP session. Do not save the file path and use it across sessions.
///
/// The [source] argument controls where the video comes from. This can
/// be either [ImageSource.camera] or [ImageSource.gallery].
///
/// The [maxDuration] argument specifies the maximum duration of the captured video. If no [maxDuration] is specified,
/// the maximum duration will be infinite.
///
/// Use `preferredCameraDevice` to specify the camera to use when the `source` is [ImageSource.camera].
/// The `preferredCameraDevice` is ignored when `source` is [ImageSource.gallery]. It is also ignored if the chosen camera is not supported on the device.
/// Defaults to [CameraDevice.rear].
///
/// In Android, the MainActivity can be destroyed for various fo reasons. If that happens, the result will be lost
/// in this call. You can then call [retrieveLostData] when your app relaunches to retrieve the lost data.
///
/// The method could throw [PlatformException] if the app does not have permission to access
/// the camera or photos gallery, no camera is available, plugin is already in use,
/// temporary file could not be created and video could not be cached (iOS only),
/// plugin activity could not be allocated (Android only) or due to an unknown error.
///
Future<XFile?> pickVideo({
required ImageSource source,
CameraDevice preferredCameraDevice = CameraDevice.rear,
Duration? maxDuration,
}) {
return platform.getVideo(
source: source,
preferredCameraDevice: preferredCameraDevice,
maxDuration: maxDuration,
);
}

/// Retrieve the lost [XFile] when [pickImage], [pickMultiImage] or [pickVideo] failed because the MainActivity
/// is destroyed. (Android only)
///
/// Image or video can be lost if the MainActivity is destroyed. And there is no guarantee that the MainActivity is always alive.
/// Call this method to retrieve the lost data and process the data according to your APP's business logic.
///
/// Returns a [LostDataResponse] object if successfully retrieved the lost data. The [LostDataResponse] object can \
/// represent either a successful image/video selection, or a failure.
///
/// Calling this on a non-Android platform will throw [UnimplementedError] exception.
///
/// See also:
/// * [LostDataResponse], for what's included in the response.
/// * [Android Activity Lifecycle](https://developer.android.com/reference/android/app/Activity.html), for more information on MainActivity destruction.
Future<LostDataResponse> retrieveLostData() {
return platform.getLostData();
}
}
Loading