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 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
4 changes: 4 additions & 0 deletions packages/image_picker/image_picker_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.5+4

* Fixes null cast exception when restoring a cancelled selection.

## 0.8.5+3

* Updates minimum Flutter version to 2.10.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.app.ActivityCompat;
import androidx.core.content.FileProvider;
Expand Down Expand Up @@ -621,11 +622,18 @@ private boolean setPendingMethodCallAndResult(
return true;
}

private void finishWithSuccess(String imagePath) {
// Handles completion of selection with a single result.
//
// A null imagePath indicates that the image picker was cancelled without
// selection.
private void finishWithSuccess(@Nullable String imagePath) {
if (pendingResult == null) {
ArrayList<String> pathList = new ArrayList<>();
pathList.add(imagePath);
cache.saveResult(pathList, null, null);
// Only save data for later retrieval if something was actually selected.
if (imagePath != null) {
ArrayList<String> pathList = new ArrayList<>();
pathList.add(imagePath);
cache.saveResult(pathList, null, null);
}
return;
}
pendingResult.success(imagePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
Expand Down Expand Up @@ -275,6 +276,16 @@ public void onActivityResult_WhenPickFromGalleryCanceled_FinishesWithNull() {
verifyNoMoreInteractions(mockResult);
}

@Test
public void onActivityResult_WhenPickFromGalleryCanceled_StoresNothingInCache() {
ImagePickerDelegate delegate = createDelegate();

delegate.onActivityResult(
ImagePickerDelegate.REQUEST_CODE_CHOOSE_IMAGE_FROM_GALLERY, Activity.RESULT_CANCELED, null);

verify(cache, never()).saveResult(any(), any(), any());
}

@Test
public void
onActivityResult_WhenImagePickedFromGallery_AndNoResizeNeeded_FinishesWithImagePath() {
Expand All @@ -287,6 +298,18 @@ public void onActivityResult_WhenPickFromGalleryCanceled_FinishesWithNull() {
verifyNoMoreInteractions(mockResult);
}

@Test
public void onActivityResult_WhenImagePickedFromGallery_AndNoResizeNeeded_StoresImageInCache() {
ImagePickerDelegate delegate = createDelegate();

delegate.onActivityResult(
ImagePickerDelegate.REQUEST_CODE_CHOOSE_IMAGE_FROM_GALLERY, Activity.RESULT_OK, mockIntent);

ArgumentCaptor<ArrayList<String>> pathListCapture = ArgumentCaptor.forClass(ArrayList.class);
verify(cache, times(1)).saveResult(pathListCapture.capture(), any(), any());
assertEquals("pathFromUri", pathListCapture.getValue().get(0));
}

@Test
public void
onActivityResult_WhenImagePickedFromGallery_AndResizeNeeded_FinishesWithScaledImagePath() {
Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: image_picker_android
description: Android implementation of the image_picker plugin.
repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/image_picker_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
version: 0.8.5+3
version: 0.8.5+4

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down