Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[image_picker] Switch unit tests to mock plaform implementation #5706

Merged
merged 3 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions packages/image_picker/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.8.5+3

* Adds argument error assertions to the app-facing package, to ensure
consistency across platform implementations.
* Updates tests to use a mock platform instead of relying on default
method channel implementation internals.

## 0.8.5+2

* Minor fixes for new analysis options.
Expand Down
22 changes: 22 additions & 0 deletions packages/image_picker/image_picker/lib/image_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ class ImagePicker {
int? imageQuality,
CameraDevice preferredCameraDevice = CameraDevice.rear,
}) {
if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) {
throw ArgumentError.value(
imageQuality, 'imageQuality', 'must be between 0 and 100');
}
if (maxWidth != null && maxWidth < 0) {
throw ArgumentError.value(maxWidth, 'maxWidth', 'cannot be negative');
}
if (maxHeight != null && maxHeight < 0) {
throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative');
}

return platform.getImage(
source: source,
maxWidth: maxWidth,
Expand Down Expand Up @@ -245,6 +256,17 @@ class ImagePicker {
double? maxHeight,
int? imageQuality,
}) {
if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) {
throw ArgumentError.value(
imageQuality, 'imageQuality', 'must be between 0 and 100');
}
if (maxWidth != null && maxWidth < 0) {
throw ArgumentError.value(maxWidth, 'maxWidth', 'cannot be negative');
}
if (maxHeight != null && maxHeight < 0) {
throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative');
}

return platform.getMultiImage(
maxWidth: maxWidth,
maxHeight: maxHeight,
Expand Down
4 changes: 3 additions & 1 deletion packages/image_picker/image_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for selecting images from the Android and iOS image
library, and taking new pictures with the camera.
repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/image_picker
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
version: 0.8.5+2
version: 0.8.5+3

environment:
sdk: ">=2.14.0 <3.0.0"
Expand All @@ -28,6 +28,8 @@ dependencies:
image_picker_platform_interface: ^2.3.0

dev_dependencies:
build_runner: ^2.1.10
cross_file: ^0.3.1+1 # Mockito generates a direct include.
flutter_test:
sdk: flutter
mockito: ^5.0.0
Expand Down
Loading