Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.10.0

* Adds limit parameter to `MediaOptions` and `MultiImagePickerOptions`.

## 2.9.4

* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
double? maxHeight,
int? imageQuality,
bool requestFullMetadata = true,
int? limit,
}) {
if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) {
throw ArgumentError.value(
Expand All @@ -72,13 +73,18 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative');
}

if (limit != null && limit < 2) {
throw ArgumentError.value(limit, 'limit', 'cannot be lower than 2');
}

return _channel.invokeMethod<List<dynamic>?>(
'pickMultiImage',
<String, dynamic>{
'maxWidth': maxWidth,
'maxHeight': maxHeight,
'imageQuality': imageQuality,
'requestFullMetadata': requestFullMetadata,
'limit': limit,
},
);
}
Expand Down Expand Up @@ -244,6 +250,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
maxHeight: options.imageOptions.maxHeight,
imageQuality: options.imageOptions.imageQuality,
requestFullMetadata: options.imageOptions.requestFullMetadata,
limit: options.limit,
);
if (paths == null) {
return <XFile>[];
Expand All @@ -263,6 +270,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
'maxImageHeight': imageOptions.maxHeight,
'imageQuality': imageOptions.imageQuality,
'allowMultiple': options.allowMultiple,
'limit': options.limit,
};

final List<XFile>? paths = await _channel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,47 @@ class MediaOptions {
const MediaOptions({
this.imageOptions = const ImageOptions(),
required this.allowMultiple,
this.limit,
});

/// Construct a new MediaOptions instance.
///
/// Throws if limit is lower than 2,
/// or allowMultiple is false and limit is not null
MediaOptions.createAndValidate({
this.imageOptions = const ImageOptions(),
required this.allowMultiple,
this.limit,
}) {
_validate(allowMultiple: allowMultiple, limit: limit);
}

/// Options that will apply to images upon selection.
final ImageOptions imageOptions;

/// Whether to allow for selecting multiple media.
final bool allowMultiple;

/// The maximum number of images to select.
///
/// Default null value means no limit.
final int? limit;

/// Validates that all values are within required ranges.
///
/// Throws if limit is lower than 2,
/// or allowMultiple is false and limit is not null.
static void _validate({required bool allowMultiple, int? limit}) {
if (!allowMultiple && limit != null) {
throw ArgumentError.value(
allowMultiple,
'allowMultiple',
'cannot be false, when limit is not null',
);
}

if (limit != null && limit < 2) {
throw ArgumentError.value(limit, 'limit', 'cannot be lower then 2');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,36 @@ import 'image_options.dart';

/// Specifies options for picking multiple images from the device's gallery.
class MultiImagePickerOptions {
/// Creates an instance with the given [imageOptions].
/// Creates an instance with the given [imageOptions] and [limit].
const MultiImagePickerOptions({
this.imageOptions = const ImageOptions(),
this.limit,
});

/// Creates an instance with the given [imageOptions] and [limit].
///
/// Throws if limit is lower than 2.
MultiImagePickerOptions.createAndValidate({
this.imageOptions = const ImageOptions(),
this.limit,
}) {
_validate(limit: limit);
}

/// The image-specific options for picking.
final ImageOptions imageOptions;

/// The maximum number of images to select.
///
/// Default null value means no limit.
final int? limit;

/// Validates that all values are within required ranges.
///
/// Throws if limit is lower than 2.
static void _validate({int? limit}) {
if (limit != null && limit < 2) {
throw ArgumentError.value(limit, 'limit', 'cannot be lower then 2');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/image_picker/
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.9.4
version: 2.10.0

environment:
sdk: ^3.3.0
Expand Down
Loading