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

Conversation

@rodydavis
Copy link
Contributor

I have added the ability to select and capture photos and videos using the stock UI on Android and iOS.

  • For Some Reason, iOS aspect ratio looks weird on the video player if it is in the portrait orientation but Android looks great

@rodydavis
Copy link
Contributor Author

Ready for Review.

Copy link
Contributor

@mravn-google mravn-google left a comment

Choose a reason for hiding this comment

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

Thank you very much for your contribution! Sorry for the review latency.

assert(source != null);

if (maxWidth != null && maxWidth < 0) {
throw new ArgumentError.value(maxWidth, 'maxWidth can\'t be negative');
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use "cannot" rather than "can't".

'maxHeight': maxHeight,
},
);
return path != null ? new File(path) : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Inverting the condition avoids the negation:

return path == null ? null : new File(path);

NSString *tmpPath = [tmpDirectory stringByAppendingPathComponent:tmpFile];
if ([[NSFileManager defaultManager] createFileAtPath:tmpPath contents:data attributes:nil]) {
_result(tmpPath);
if (videoURL != nil) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we avoid working on the image above, if videoURL is not nil? Seems to be wasted effort.

];
_imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;

_result = result;
Copy link
Contributor

Choose a reason for hiding this comment

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

The code from here and until line 102 appears to be a copy of the image case. Could we refactor to avoid the duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would a shared function containing the shared code be better for this? I duplicated it so I could provide different errors in the result.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll leave it up to you.

@@ -1,11 +1,14 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this empty line.

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.

ARCHS = arm64;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 3GRKCVVJ22;
DEVELOPMENT_TEAM = 9FK3425VTA;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the DEVELOPMENT_TEAM lines.

}

// -- Photo --
// Choose Photo from Gallery
Copy link
Contributor

Choose a reason for hiding this comment

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

These comments provide very little information on top of the name of the method.

}

// -- Video --
// Choose Video From Gallery
Copy link
Contributor

Choose a reason for hiding this comment

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

These comments provide very little information on top of the name of the method.

@@ -0,0 +1,14 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the .vscode/ folders be .gitignored or are they intended to be shared between developers using that IDE?

## 0.4.2

* Added Video Capability with `pickVideo`.
* Updated Example for Preview of Video Captured
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use full verb phrases using standard US spelling and capitalization. E.g.

* Added support for picking videos.
* Updated example app to show video preview.

Copy link
Contributor

@mravn-google mravn-google left a comment

Choose a reason for hiding this comment

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

Thanks!

..initialize()
..setLooping(true)
..play();
setState(() {});
Copy link
Contributor

Choose a reason for hiding this comment

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

  • By convention, state changes are made within the lambda given to setState. Not that it matters much to runtime behavior, but because empty setState(() {}) calls like this are very easy to overlook, forget, or place where not needed. I believe an early version of Flutter had a markNeedsBuild() method or similar which was replaced by setState for exactly this reason.
  • Since setState is called on completion of the pickVideo future, the State we're in may have been unmounted in the meantime. We therefore need to guard the call to setState with a check on the mounted property:
    if (file != null && mounted) {
      setState(() {
        _controller = ...
      });
    }
    An alternative is to use a FutureBuilder as for images. It does the mounted check internally.

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove eclipse artifacts from the repo (.classpath, .project, .settings/).

.gitignore Outdated
.dart_tool
.dart_tool
packages/image_picker/.vscode/launch.json
packages/image_picker/.vscode/settings.json
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't want plugin-specific lines in the repo-level .gitignore. Please replace these two lines by

.vscode/

@@ -0,0 +1,19 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove file.
FYI, #588 adds the needed .gitignore for .vscode/ to the repo root.

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove file.

@@ -0,0 +1,2 @@
#Thu May 24 08:04:52 EDT 2018
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove file.

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove file.

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove file.

@@ -0,0 +1,2 @@
#Thu May 24 08:04:52 EDT 2018
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove file.

}
}

class AspectRatioVideo extends StatefulWidget {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we reduce code duplication from video_player/example to the bare minimum, please?

The image_picker example should be focused on the functionality of image/video picking, not video playback. I think having the AspectRatioVideo widget here is OK, but I don't think we need play/pause controls for this example. And the buildCard method further below is not used at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay sounds good. View-Only of the video works too. I had brought that over from the video player example because when the video is looping it will play noise and the user may want to silence it. But it should be up to the developer to implement playback anyway. I can remove everything but the viewer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. The merge conflict happens because I just removed all .gitignore files except the repo root one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I resolved the conflict. Vscode seems to generate a lot of extra files everytime the project is run. Ill see if Android Studio is doing the same thing

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why Vscode generates eclipse project files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure. maybe an extension in Vscode doing it. Ill check it out.

Copy link
Contributor

@mravn-google mravn-google left a comment

Choose a reason for hiding this comment

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

LGTM

return new Container();
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add empty line at the end of the file.

Copy link
Contributor Author

@rodydavis rodydavis May 25, 2018

Choose a reason for hiding this comment

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

When I add an empty line it failed the format test?

.gitignore Outdated
GeneratedPluginRegistrant.h
GeneratedPluginRegistrant.m
GeneratedPluginRegistrant.java

Copy link
Contributor

Choose a reason for hiding this comment

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

No need for this change.

@mravn-google
Copy link
Contributor

I get an exception when picking an image:

D/AndroidRuntime(12078): Shutting down VM
E/AndroidRuntime(12078): FATAL EXCEPTION: main
E/AndroidRuntime(12078): Process: io.flutter.plugins.imagepicker.example, PID: 12078
E/AndroidRuntime(12078): java.lang.RuntimeException: Unable to resume activity {io.flutter.plugins.imagepicker.example/io.flutter.plugins.imagepickerexample.MainActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2342, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:11165 flg=0x1 }} to activity {io.flutter.plugins.imagepicker.example/io.flutter.plugins.imagepickerexample.MainActivity}: java.lang.IllegalStateException: Received images from picker that were not requested
E/AndroidRuntime(12078): 	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3581)
E/AndroidRuntime(12078): 	at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3621)
E/AndroidRuntime(12078): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2862)
E/AndroidRuntime(12078): 	at android.app.ActivityThread.-wrap11(Unknown Source:0)
E/AndroidRuntime(12078): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
E/AndroidRuntime(12078): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(12078): 	at android.os.Looper.loop(Looper.java:164)
E/AndroidRuntime(12078): 	at android.app.ActivityThread.main(ActivityThread.java:6494)
E/AndroidRuntime(12078): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(12078): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E/AndroidRuntime(12078): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
E/AndroidRuntime(12078): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2342, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:11165 flg=0x1 }} to activity {io.flutter.plugins.imagepicker.example/io.flutter.plugins.imagepickerexample.MainActivity}: java.lang.IllegalStateException: Received images from picker that were not requested
E/AndroidRuntime(12078): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:4268)
E/AndroidRuntime(12078): 	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3553)
E/AndroidRuntime(12078): 	... 10 more
E/AndroidRuntime(12078): Caused by: java.lang.IllegalStateException: Received images from picker that were not requested
E/AndroidRuntime(12078): 	at io.flutter.plugins.imagepicker.ImagePickerDelegate.handleResult(ImagePickerDelegate.java:392)
E/AndroidRuntime(12078): 	at io.flutter.plugins.imagepicker.ImagePickerDelegate.handleChoosePictureResult(ImagePickerDelegate.java:359)
E/AndroidRuntime(12078): 	at io.flutter.plugins.imagepicker.ImagePickerDelegate.onActivityResult(ImagePickerDelegate.java:346)
E/AndroidRuntime(12078): 	at io.flutter.app.FlutterPluginRegistry.onActivityResult(FlutterPluginRegistry.java:194)
E/AndroidRuntime(12078): 	at io.flutter.app.FlutterActivityDelegate.onActivityResult(FlutterActivityDelegate.java:146)
E/AndroidRuntime(12078): 	at io.flutter.app.FlutterActivity.onActivityResult(FlutterActivity.java:139)
E/AndroidRuntime(12078): 	at android.app.Activity.dispatchActivityResult(Activity.java:7276)
E/AndroidRuntime(12078): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:4264)
E/AndroidRuntime(12078): 	... 11 more
Lost connection to device.

@rodydavis
Copy link
Contributor Author

rodydavis commented May 27, 2018

Go into the app settings to enable all permissions, I will double check it’s requesting the permissions correctly and update as necessary. It is working for me on the Google Pixel which android phone are you testing on?

I had had this error when i didn’t have read/write storage permissions granted one time.

@mravn-google
Copy link
Contributor

mravn-google commented May 27, 2018

@AppleEducate Turns out I had the System/Developer options/Don't keep activities option enabled on my Nexus 5X, so the Flutter activity was killed as soon as I launched the native counterpart. The plugin isn't working in this situation on master either, cf. flutter/flutter#17950.

@mravn-google mravn-google merged commit 34962b5 into flutter:master May 27, 2018
@rodydavis
Copy link
Contributor Author

Gotcha! Good to know 👍🏻

@diegoveloper
Copy link
Member

Hi @AppleEducate , do you know if the issue that you mentioned was fixed?

For Some Reason, iOS aspect ratio looks weird on the video player if it is in the portrait orientation but Android looks great

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants