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

[image_picker] Handle all images through URI #2728

Merged
merged 7 commits into from May 5, 2020

Conversation

cyanglaz
Copy link
Contributor

@cyanglaz cyanglaz commented May 1, 2020

Description

For some historical reason, we have separated the diverged the code to different paths when handling different types of image data. Really, we should always handle the picked image through an URI like what we have been doing for remote images.
This way we can make sure the image picked from URI is definitely usable in the APP.

We don't seem to have a good way to test changes around this code base. I will keep looking into ways to test with JUnit
I have manually tested with downloaded images, images taken from camera, and images from google driver.
Tested with pixel a3 android 11, and some older android builds in emulators.

Related Issues

b/155138680
flutter/flutter#41459

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@cyanglaz cyanglaz changed the title [image_picker] Handle all images from uri [WIP][image_picker] Handle all images from uri May 1, 2020
@@ -147,6 +42,7 @@ private static String getPathFromRemoteUri(final Context context, final Uri uri)
String extension = getImageExtension(uri);
inputStream = context.getContentResolver().openInputStream(uri);
file = File.createTempFile("image_picker", extension, context.getCacheDir());
file.deleteOnExit();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a new change to the previous code. I think we really should just try to delete the temp file after the virtual machine exits.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 Especially since these files can get large.

Although this would imply the apps should not be storing the File URI anywhere. I don't think we currently recommend that in the documentation. We should fix that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, will update the doc as well!

@cyanglaz cyanglaz requested a review from xster May 1, 2020 19:18
@cyanglaz cyanglaz changed the title [WIP][image_picker] Handle all images from uri [image_picker] Handle all images from uri May 1, 2020
@cyanglaz cyanglaz changed the title [image_picker] Handle all images from uri [image_picker] Handle all images through URI May 1, 2020
@cyanglaz cyanglaz requested a review from mehmetf May 1, 2020 22:35
@cyanglaz
Copy link
Contributor Author

cyanglaz commented May 4, 2020

@xster Added the tests, PTAL
@mehmetf Updated the doc, PTAL

assertTrue(path.contains("image_picker"));
assertTrue(path.contains("png"));
assertTrue(path.contains("/cache/"));
}
Copy link
Member

Choose a reason for hiding this comment

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

you "may" be able to just read from the path and assert that the content are the bytes for the string imageStream too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

very nice! thanks

@xster
Copy link
Member

xster commented May 4, 2020

Great. Thanks for adding the test. LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
4 participants