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

[image_picker] added methodCall arg: deleteCapturedOriginalIfScaled#1463

Closed
sensiblearts wants to merge 2 commits intoflutter:masterfrom
sensiblearts:master
Closed

[image_picker] added methodCall arg: deleteCapturedOriginalIfScaled#1463
sensiblearts wants to merge 2 commits intoflutter:masterfrom
sensiblearts:master

Conversation

@sensiblearts
Copy link
Copy Markdown

Description

Your image_picker changelog

0.5.0+6
Delete the original image if it was scaled.

broke my business logic.

The fix is a very small change: add a methodCall param. I have only fixed Android:

 ImagePicker.pickImage(source: source, maxWidth: 600.0, deleteCapturedOriginalIfScaled: false).then((File image) {
...

(Specifically, my business logic needs: I was using the image_picker to capture scaled images (e.g., maxWidth = 600.0) but also keeping the original (non-scaled) image long enough to copy it to external storage; after I copied it, I manually deleted the original image.)

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.

@googlebot
Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@sensiblearts
Copy link
Copy Markdown
Author

sensiblearts commented Apr 8, 2019 via email

@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels Apr 8, 2019
@collinjackson collinjackson changed the title added methodCall arg: deleteCapturedOriginalIfScaled [image_picker] added methodCall arg: deleteCapturedOriginalIfScaled Apr 9, 2019
@collinjackson collinjackson requested a review from cyanglaz April 9, 2019 00:59
@cyanglaz
Copy link
Copy Markdown
Contributor

cyanglaz commented Apr 9, 2019

@sensiblearts Thank you for providing this PR. I understand your needs to save the original image. However, I am not confident enough to take a public API change that only adds new features to Android right now. I will take some time to review the possibility of doing this on iOS side and maybe provide a solution to benefit both platforms. If you do need this urgently, I suggest you to make the change on your own fork. Or you can use the earlier version of the image picker.

I have created an issue to track this flutter/flutter#30788, you can follow the issue and get updates on progress of this fix.

I will leave this PR open for now, if you'd like to provide the changes on iOS and also adding tests to this change, you are welcome to do so and I am happy to review the changes.

@sensiblearts
Copy link
Copy Markdown
Author

@cyanglaz Thank you for the quick reply.

I will eventually get to iOS version myself, as well as tests, but it will be a month or so.

However, I just discovered that I need to make a breaking change, and I doubt whether it will be general enough to pull; consequently, I am assuming that I will be maintaining my own fork indefinitely.

FYI, here is the breaking change in my fork:

Problem to solve:

  • I need both scaled and original files retained
  • I need the original filename even if it was selected from a folder

Whereas I can derive the original filename from the scaled filename in case of capture, I cannot do this if the user picks a random file in a folder. Therefore, the simplest way to get this string is to have the plugin return it.

So, I modified image_picker.dart to return a custom class:

class PickedFile {
  PickedFile({this.original, this.scaled, this.video});
  File original;
  File scaled;
  File video;
}

class ImagePicker {
 //...
  static Future<PickedFile> pickImage({
 /...
    final Map<dynamic, dynamic> pickedPath = await _channel.invokeMethod(
      'pickImage',
 //...
   );
    final PickedFile pf = PickedFile(
        original: pickedPath["original"] == null
            ? null
            : File(pickedPath["original"]),
        scaled:
            pickedPath["scaled"] == null ? null : File(pickedPath["scaled"]),
        video: null);
    return pf;
  }

  static Future<PickedFile> pickVideo({
//...
    final Map<dynamic, dynamic> pickedPath = await _channel.invokeMethod(
      'pickVideo',
   //...
    final PickedFile pf = PickedFile(
        original: null,
        scaled: null,
        video: pickedPath["video"] == null ? null : File(pickedPath["video"]));
    return pf;
  }
}

This code is in a separate branch called 'picked_file' and it is solving this problem described above.

Thanks for your time,
DA

@cyanglaz
Copy link
Copy Markdown
Contributor

@sensiblearts
I am going to close this PR if you don't mind since it is not complete yet. (No iOS implementation). You can follow the issue I created for progress on this. Also you are more then welcomed to open a new PR if you get the iOS code ready! Thank you again for the contribution!

@cyanglaz cyanglaz closed this Apr 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants