Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.5.0

* Re-adds `requestFullMetadata` option, but as a parameter of a new `pickImageFromSource`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's mention all the changes in this PR in details, such as:
Deprecated getImage (We should do this too in this PR)
Added getImageFromSource
Added ImagePickerOptions,
Added requestFullMetadata

method.

## 2.4.4

* Internal code cleanup for stricter analysis options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
double? maxHeight,
int? imageQuality,
CameraDevice preferredCameraDevice = CameraDevice.rear,
bool requestFullMetadata = true,
}) {
if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) {
throw ArgumentError.value(
Expand All @@ -108,7 +109,8 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
'maxWidth': maxWidth,
'maxHeight': maxHeight,
'imageQuality': imageQuality,
'cameraDevice': preferredCameraDevice.index
'cameraDevice': preferredCameraDevice.index,
'requestFullMetadata': requestFullMetadata,
},
);
}
Expand Down Expand Up @@ -197,6 +199,22 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
return path != null ? XFile(path) : null;
}

@override
Future<XFile?> getImageFromSource({
required ImageSource source,
ImagePickerOptions options = const ImagePickerOptions(),
}) async {
final String? path = await _getImagePath(
source: source,
maxHeight: options.maxHeight,
maxWidth: options.maxWidth,
imageQuality: options.imageQuality,
preferredCameraDevice: options.preferredCameraDevice,
requestFullMetadata: options.requestFullMetadata,
);
return path != null ? XFile(path) : null;
}

@override
Future<List<XFile>?> getMultiImage({
double? maxWidth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ abstract class ImagePickerPlatform extends PlatformInterface {
throw UnimplementedError('retrieveLostData() has not been implemented.');
}

/// This method is deprecated in favor of [getImageFromSource] and will be removed in a future update.
///
/// Returns an [XFile] with the image that was picked.
///
/// The `source` argument controls where the image comes from. This can
Expand Down Expand Up @@ -251,4 +253,32 @@ abstract class ImagePickerPlatform extends PlatformInterface {
Future<LostDataResponse> getLostData() {
throw UnimplementedError('getLostData() has not been implemented.');
}

/// Returns an [XFile] with the image that was picked.
///
/// The `source` argument controls where the image comes from. This can
/// be either [ImageSource.camera] or [ImageSource.gallery].
///
/// The `options` argument controls additional settings that can be used when picking an image. See [ImagePickerOptions]
/// for more details.
///
/// 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 in [ImagePickerOptions].
///
/// 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 [getLostData] when your app relaunches to retrieve the lost data.
///
/// If no images were picked, the return value is null.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap all the lines in this comment block to 80 characters.

Future<XFile?> getImageFromSource({
required ImageSource source,
ImagePickerOptions options = const ImagePickerOptions(),
}) {
return getImage(
source: source,
maxHeight: options.maxHeight,
maxWidth: options.maxWidth,
imageQuality: options.imageQuality,
preferredCameraDevice: options.preferredCameraDevice,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:image_picker_platform_interface/src/types/types.dart';

/// Specifies options for picking a single image from the device's camera or gallery.
class ImagePickerOptions {
/// Creates an instance with the given [maxHeight], [maxWidth], [imageQuality],
/// [referredCameraDevice] and [requestFullMetadata]. Any of the params may be null.
const ImagePickerOptions({
this.maxHeight,
this.maxWidth,
this.imageQuality,
this.preferredCameraDevice = CameraDevice.rear,
this.requestFullMetadata = true,
});

/// If specified, the image will be at most `maxWidth` wide. Otherwise,
/// the image will be returned at its original width.
final double? maxWidth;

/// If specified, the image will be at most`maxHeight` tall.
/// Otherwise the image will be returned at its original height.
final double? maxHeight;

/// 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 originalquality will
/// be returned. Compression is only supported for certain image types such as
/// JPEG. If compression is not supported for the image that is picked, a warning
/// message will be logged.
final int? imageQuality;

/// Used 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.
final CameraDevice preferredCameraDevice;

/// `requestFullMetadata` defaults to `true`, so the plugin tries to get the
/// full image metadata which may require extra permission requests on certain platforms.
/// If `requestFullMetadata` is set to `false`, the plugin fetches the image
/// in a way that reduces permission requests from the platform (e.g. on iOS
/// the plugin won’t ask for the `NSPhotoLibraryUsageDescription` permission).
final bool requestFullMetadata;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

export 'camera_device.dart';
export 'image_picker_options.dart';
export 'image_source.dart';
export 'lost_data_response.dart';
export 'picked_file/picked_file.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/i
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.4.4
version: 2.5.0

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
Loading