Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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
3 changes: 2 additions & 1 deletion packages/image_picker/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 0.8.7+2

* Example file showcases how to display an error placeholder whenever an unsupported image type is selected.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We generally describe the change with a verb. E.g., "Adds handling of unsupported image types to the example."

* Updates minimum Flutter version to 3.3.

## 0.8.7+1
Expand Down
8 changes: 7 additions & 1 deletion packages/image_picker/image_picker/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ class _MyHomePageState extends State<MyHomePage> {
label: 'image_picker_example_picked_image',
child: kIsWeb
? Image.network(_imageFileList![index].path)
: Image.file(File(_imageFileList![index].path)),
: Image.file(
File(_imageFileList![index].path),
errorBuilder: (BuildContext context, Object error,
StackTrace? stackTrace) =>
const Center(
child: Text('This image type is not supported')),
),
);
},
itemCount: _imageFileList!.length,
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/packages/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.7+1
version: 0.8.7+2

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/image_picker/image_picker_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 0.8.6+7

* Non-bitmap images return path instead of null.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Fixes handling of non-bitmap image types."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the PR with the changes, thank you for the review 🙏🏻.

* Updates minimum Flutter version to 3.3.

## 0.8.6+6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ private void launchPickImageFromGalleryIntent(Boolean useAndroidPhotoPicker) {
pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
pickImageIntent.setType("image/*");
}

activity.startActivityForResult(pickImageIntent, REQUEST_CODE_CHOOSE_IMAGE_FROM_GALLERY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ String resizeImageIfNeeded(
String imagePath, @Nullable Double maxWidth, @Nullable Double maxHeight, int imageQuality) {
Bitmap bmp = decodeFile(imagePath);
if (bmp == null) {
return null;
return imagePath;
}
boolean shouldScale = maxWidth != null || maxHeight != null || imageQuality < 100;
if (!shouldScale) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertNotNull;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
Expand All @@ -16,6 +17,8 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;

Expand All @@ -26,6 +29,7 @@ public class ImageResizerTest {

ImageResizer resizer;
File imageFile;
File svgImageFile;
File externalDirectory;
Bitmap originalImageBitmap;

Expand All @@ -35,6 +39,7 @@ public class ImageResizerTest {
public void setUp() throws IOException {
mockCloseable = MockitoAnnotations.openMocks(this);
imageFile = new File(getClass().getClassLoader().getResource("pngImage.png").getFile());
svgImageFile = new File(getClass().getClassLoader().getResource("flutter_image.svg").getFile());
originalImageBitmap = BitmapFactory.decodeFile(imageFile.getPath());
TemporaryFolder temporaryFolder = new TemporaryFolder();
temporaryFolder.create();
Expand Down Expand Up @@ -78,4 +83,23 @@ public void onResizeImageIfNeeded_whenParentDirectoryDoesNotExists_shouldNotCras
String outputFile = invalidResizer.resizeImageIfNeeded(imageFile.getPath(), null, 50.0, 100);
assertThat(outputFile, equalTo(nonExistentDirectory.getPath() + "/scaled_pngImage.png"));
}

@Test
public void onResizeImageIfNeeded_whenImagePathIsNotBitmap_shouldReturnPathAndNotNull() {
String nonBitmapImagePath = svgImageFile.getPath();

// Mock the static method
try (MockedStatic<BitmapFactory> mockedBitmapFactory =
Mockito.mockStatic(BitmapFactory.class)) {
// Configure the method to return null when called with a non-bitmap image
mockedBitmapFactory
.when(() -> BitmapFactory.decodeFile(nonBitmapImagePath, null))
.thenReturn(null);

String resizedImagePath = resizer.resizeImageIfNeeded(nonBitmapImagePath, null, null, 100);

assertNotNull(resizedImagePath);
assertThat(resizedImagePath, equalTo(nonBitmapImagePath));
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ -3,7 +3,7 @@ description: Android implementation of the image_picker plugin.
repository: https://github.com/flutter/packages/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.6+6
version: 0.8.6+7

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down