Thanks to visit codestin.com
Credit goes to github.com

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

[image_picker] Added image_picker_for_windows. #4863

Merged
merged 23 commits into from
Apr 21, 2022

Conversation

azchohfi
Copy link
Contributor

@azchohfi azchohfi commented Feb 15, 2022

This PR adds a very simplistic Windows implementation of the image_picker plugin, which uses the file_selector plugin to get images or videos from the "gallery". This initial implementation doesn't yet support ImageSource.camera (falls back to gallery).

Fixes flutter/flutter#92108

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

Looks good! This will need Dart unit tests that sets a mock FileSelectorPlatform implementation as FileSelectorPlatform.instance and validates that the expected calls are made. And also that registerWith works (as in other Dart plugin implementation tests).

While the logic is currently pretty trivial, having tests in place is important as we change it over time.

@azchohfi
Copy link
Contributor Author

I believe I got it all. Let me know if there is anything missing.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

Just a few more minor things, sorry I missed some of these on the first review. Thanks for implementing this!

Adding @cbracken for secondary review.

@azchohfi azchohfi force-pushed the image_picker_win_fs branch from d5e2767 to 59b831d Compare February 17, 2022 19:36
@azchohfi
Copy link
Contributor Author

Oh, I believe I need to add the image_picker_windows to the exclude_integration_win32.yaml file.

@azchohfi
Copy link
Contributor Author

@stuartmorgan anything else needed here?

@stuartmorgan-g
Copy link
Contributor

Sorry for the slow response, I haven't had much time for reviews because of the build issue with VS 17.1.0.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

A few other small things, but otherwise it should be good from my side.

expect(
log,
<Matcher>[
isMethodCall('openFile', arguments: <String, dynamic>{
Copy link
Contributor

Choose a reason for hiding this comment

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

You are testing implementation details of file_selector here; these tests would all break if FileSelectorWindows changed its implementation (e.g., switched to a Dart implementation, or to using Pigeon).

Even though you can't use FileSelectorPlatform.instance in the implementation, you can still write the implementation against a FileSelectorPlatform variable, and just manually instantiate it with a FileSelectorWindows. Then you can make that instance settable by tests, and insert a mock implementation in these tests and validate against that mock. Then it doesn't matter how FileSelectorWindows works, because you'll just be verifying that you're using its API correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stuartmorgan I just pushed the changes. I believe that is what you means, which I agree that is a way better approach.

@azchohfi
Copy link
Contributor Author

@stuartmorgan anything needed here?

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

One comment about adding a few more tests, but LGTM otherwise. The main thing this is waiting on is just the second review from @cbracken.

@azchohfi
Copy link
Contributor Author

@cbracken anything else needed here?

@azchohfi
Copy link
Contributor Author

Merged main into this branch just to keep it up to date.
@stuartmorgan / @cbracken let me know if there is anything else needed here.

@azchohfi
Copy link
Contributor Author

azchohfi commented Apr 7, 2022

Merged main again, just to keep this updated. Unlike the local_auth plugin, the image_picker plugin is already federated. @stuartmorgan / @cbracken what is keeping this PR from being reviewed/merged?

@stuartmorgan-g
Copy link
Contributor

@stuartmorgan / @cbracken what is keeping this PR from being reviewed/merged?

It's still @cbracken having time to review; Flutter policy requires two reviews for PRs from people outside the org before landing.

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

Overall looks good! Just a few comments.

await _playVideo(file);
} else if (isMultiImage) {
await _displayPickImageDialog(context!,
(double? maxWidth, double? maxHeight, int? quality) async {
Copy link
Member

Choose a reason for hiding this comment

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

Optionally, consider breaking this out to a separate private method like _handleMultiImagePicked to reduce the amount of handling directly under _onImageButtonPressed.

});
} else {
await _displayPickImageDialog(context!,
(double? maxWidth, double? maxHeight, int? quality) async {
Copy link
Member

Choose a reason for hiding this comment

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

Similar comment here; something like _handleSingleImagePicked.

}

dynamic _pickImageError;
bool isVideo = false;
Copy link
Member

Choose a reason for hiding this comment

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

Consider making this private.

bool isVideo = false;

VideoPlayerController? _controller;
VideoPlayerController? _toBeDisposed;
Copy link
Member

Choose a reason for hiding this comment

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

Since there's a little complexity around the use of this field, add a doc comment explaining how it's used.

@azchohfi azchohfi requested a review from cbracken April 18, 2022 22:46
@azchohfi
Copy link
Contributor Author

@cbracken let me know what you think.

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

LGTM stamp from a Japanese personal seal

Thanks!

@stuartmorgan-g stuartmorgan-g added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Apr 21, 2022
@fluttergithubbot fluttergithubbot merged commit 92a1ffe into flutter:main Apr 21, 2022
@azchohfi azchohfi deleted the image_picker_win_fs branch April 21, 2022 18:45
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 22, 2022
cassioso pushed a commit to cassioso/plugins that referenced this pull request May 10, 2022
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: image_picker platform-windows waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[image_picker] Windows support
4 participants