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/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.1+3

* Fix image picker causing a crash when the cache directory is deleted.

## 0.8.1+2

* Update the example app to support the multi-image feature.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ private File createTemporaryWritableFile(String suffix) {
File image;

try {
externalFilesDirectory.mkdirs();
image = File.createTempFile(filename, suffix, externalFilesDirectory);
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import java.io.File;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
Expand All @@ -47,6 +48,7 @@ public class ImagePickerDelegateTest {
@Mock ImagePickerCache cache;

ImagePickerDelegate.FileUriResolver mockFileUriResolver;
MockedStatic<File> mockStaticFile;

private static class MockFileUriResolver implements ImagePickerDelegate.FileUriResolver {
@Override
Expand All @@ -64,6 +66,11 @@ public void getFullImagePath(Uri imageUri, ImagePickerDelegate.OnPathReadyListen
public void setUp() {
MockitoAnnotations.initMocks(this);

mockStaticFile = Mockito.mockStatic(File.class);
mockStaticFile
.when(() -> File.createTempFile(any(), any(), any()))
.thenReturn(new File("/tmpfile"));

when(mockActivity.getPackageName()).thenReturn("com.example.test");
when(mockActivity.getPackageManager()).thenReturn(mock(PackageManager.class));

Expand All @@ -87,6 +94,11 @@ public void setUp() {
when(mockIntent.getData()).thenReturn(mockUri);
}

@After
public void tearDown() {
mockStaticFile.close();
}

@Test
public void whenConstructed_setsCorrectFileProviderName() {
ImagePickerDelegate delegate = createDelegate();
Expand Down Expand Up @@ -195,11 +207,6 @@ public void takeImageWithCamera_WritesImageToCacheDirectory() {
when(mockPermissionManager.isPermissionGranted(Manifest.permission.CAMERA)).thenReturn(true);
when(mockIntentResolver.resolveActivity(any(Intent.class))).thenReturn(true);

MockedStatic<File> mockStaticFile = Mockito.mockStatic(File.class);
mockStaticFile
.when(() -> File.createTempFile(any(), any(), any()))
.thenReturn(new File("/tmpfile"));

ImagePickerDelegate delegate = createDelegate();
delegate.takeImageWithCamera(mockMethodCall, mockResult);

Expand Down Expand Up @@ -380,7 +387,7 @@ private ImagePickerDelegate createDelegate() {
private ImagePickerDelegate createDelegateWithPendingResultAndMethodCall() {
return new ImagePickerDelegate(
mockActivity,
null,
new File("/image_picker_cache"),
mockImageResizer,
mockResult,
mockMethodCall,
Expand Down
2 changes: 1 addition & 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/master/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.1+2
version: 0.8.1+3

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