Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e81b561
Merge pull request #1 from flutter/master
rodydavis May 10, 2018
6f35340
Adding Video Record and Selection for Android and iOS
rodydavis May 11, 2018
3b660f5
Fixing Null Error on Video Selection
rodydavis May 11, 2018
a1143e4
Updating Number
rodydavis May 11, 2018
54c3f68
Updating Formating
rodydavis May 11, 2018
4f3b1c3
Rolling Back Number
rodydavis May 11, 2018
74f775d
Updating Formating
rodydavis May 11, 2018
1fb8bf7
Revert "Updating Formating"
rodydavis May 11, 2018
86d5e88
Revert "Revert "Updating Formating""
rodydavis May 11, 2018
eaa2f8d
Revert "Revert "Revert "Updating Formating"""
rodydavis May 11, 2018
c6e35da
Revert "Rolling Back Number"
rodydavis May 11, 2018
7e83b8f
Revert "Updating Formating"
rodydavis May 11, 2018
ae48534
Revert "Updating Number"
rodydavis May 11, 2018
97bc60d
Updating Formatting
rodydavis May 11, 2018
95b6bb3
Updating Formatting
rodydavis May 11, 2018
d7d342e
Updating Formatting Based on Google Style Guide
rodydavis May 11, 2018
ffe05d0
Fixing Spacing
rodydavis May 11, 2018
06d837e
Updating Formatting based on Test Fail
rodydavis May 11, 2018
9754383
Working on Fixing Failed Tests
rodydavis May 11, 2018
ddd770c
Update main.dart
rodydavis May 16, 2018
a2ee99d
Updated Authors
rodydavis May 16, 2018
fd38d12
Update CHANGELOG.md
rodydavis May 16, 2018
bfc5dc9
Adding Video Player
rodydavis May 16, 2018
3a2f735
Updating Dependencies
rodydavis May 16, 2018
883f99d
Updating Stying
rodydavis May 16, 2018
dd9ef1f
Update main.dart
rodydavis May 16, 2018
111d568
Updating Project with PR Changes
rodydavis May 24, 2018
16ea638
Ignoring .vscode files
rodydavis May 24, 2018
2a30285
Removing Comments and Updating Changelog
rodydavis May 24, 2018
af2d018
Updating Changes for PR
rodydavis May 24, 2018
ce609b4
Fixing Formatting
rodydavis May 24, 2018
cd7e45f
Refactoring for PR
rodydavis May 24, 2018
d56aa5a
Updating Format
rodydavis May 24, 2018
e4c025b
Update .gitignore
rodydavis May 25, 2018
5a580bf
Updating Set State
rodydavis May 25, 2018
8161e02
Removing .settings .project .classpath
rodydavis May 25, 2018
e0f0d62
Merge branch 'image_picker_video' of https://github.com/AppleEducate/…
rodydavis May 25, 2018
f8ffc37
Removing Files
rodydavis May 25, 2018
b39d2fa
Updating Example
rodydavis May 25, 2018
a67bf89
Merge branch 'master' into image_picker_video
rodydavis May 25, 2018
9f73d2d
Adding Line
rodydavis May 25, 2018
e1b1075
Merge branch 'image_picker_video' of https://github.com/AppleEducate/…
rodydavis May 25, 2018
1ce00fb
Update .gitignore
rodydavis May 25, 2018
f962130
Update main.dart
rodydavis May 25, 2018
494de63
Update main.dart
rodydavis May 25, 2018
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ 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.

.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/

14 changes: 0 additions & 14 deletions packages/image_picker/.vscode/launch.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/image_picker/.vscode/settings.json

This file was deleted.

4 changes: 2 additions & 2 deletions packages/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## 0.4.2

* Added Video Capability with `pickVideo`.
* Updated Example for Preview of Video Captured
* Added support for picking videos.
* Updated example app to show video preview.

## 0.4.1

Expand Down
6 changes: 6 additions & 0 deletions packages/image_picker/android/.classpath
Original file line number Diff line number Diff line change
@@ -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/).

<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin"/>
</classpath>
23 changes: 23 additions & 0 deletions packages/image_picker/android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>image_picker</name>
<comment>Project image_picker created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Thu May 24 08:04:53 EDT 2018
connection.project.dir=../example/android
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ public void onScanCompleted(String path, Uri uri) {
this.fileUtils = fileUtils;
}

// -- Video --
// Choose Video From Gallery
public void chooseVideoFromGallery(MethodCall methodCall, MethodChannel.Result result) {
if (!setPendingMethodCallAndResult(methodCall, result)) {
finishWithAlreadyActiveError();
Expand All @@ -204,7 +202,6 @@ private void launchPickVideoFromGalleryIntent() {
activity.startActivityForResult(pickImageIntent, REQUEST_CODE_CHOOSE_FROM_GALLERY);
}

// Take a New Video
public void takeVideoWithCamera(MethodCall methodCall, MethodChannel.Result result) {
if (!setPendingMethodCallAndResult(methodCall, result)) {
finishWithAlreadyActiveError();
Expand Down Expand Up @@ -238,8 +235,6 @@ private void launchTakeVideoWithCameraIntent() {
activity.startActivityForResult(intent, REQUEST_CODE_TAKE_WITH_CAMERA);
}

// -- Photo --
// Choose Photo from Gallery
public void chooseImageFromGallery(MethodCall methodCall, MethodChannel.Result result) {
if (!setPendingMethodCallAndResult(methodCall, result)) {
finishWithAlreadyActiveError();
Expand All @@ -262,7 +257,6 @@ private void launchPickImageFromGalleryIntent() {
activity.startActivityForResult(pickImageIntent, REQUEST_CODE_CHOOSE_FROM_GALLERY);
}

// Take New Photo
public void takeImageWithCamera(MethodCall methodCall, MethodChannel.Result result) {
if (!setPendingMethodCallAndResult(methodCall, result)) {
finishWithAlreadyActiveError();
Expand Down
17 changes: 17 additions & 0 deletions packages/image_picker/example/android/.project
Original file line number Diff line number Diff line change
@@ -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.

<projectDescription>
<name>android</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -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.

connection.project.dir=
6 changes: 6 additions & 0 deletions packages/image_picker/example/android/app/.classpath
Original file line number Diff line number Diff line change
@@ -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.

<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin"/>
</classpath>
23 changes: 23 additions & 0 deletions packages/image_picker/example/android/app/.project
Original file line number Diff line number Diff line change
@@ -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.

<projectDescription>
<name>app</name>
<comment>Project app created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -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.

connection.project.dir=..
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@
buildSettings = {
ARCHS = arm64;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 9FK3425VTA;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -461,7 +460,6 @@
buildSettings = {
ARCHS = arm64;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 9FK3425VTA;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down
24 changes: 13 additions & 11 deletions packages/image_picker/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {
Future<File> _mediaFile;
Future<File> _imageFile;
bool isVideo = false;
VideoPlayerController _controller;
VoidCallback listener;
Expand All @@ -45,17 +45,19 @@ class _MyHomePageState extends State<MyHomePage> {
_controller.removeListener(listener);
}
if (isVideo) {
_mediaFile = ImagePicker.pickVideo(source: source).then((File _file) {
_controller = VideoPlayerController.file(_file)
..addListener(listener)
..setVolume(1.0)
..initialize()
..setLooping(true)
..play();
setState(() {});
ImagePicker.pickVideo(source: source).then((File file) {
if (file != null) {
_controller = VideoPlayerController.file(file)
..addListener(listener)
..setVolume(1.0)
..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.

}
});
} else {
_mediaFile = ImagePicker.pickImage(source: source);
_imageFile = ImagePicker.pickImage(source: source);
}
});
}
Expand Down Expand Up @@ -106,7 +108,7 @@ class _MyHomePageState extends State<MyHomePage> {

Widget _previewImage() {
return FutureBuilder<File>(
future: _mediaFile,
future: _imageFile,
builder: (BuildContext context, AsyncSnapshot<File> snapshot) {
if (snapshot.connectionState == ConnectionState.done &&
snapshot.data != null) {
Expand Down
24 changes: 12 additions & 12 deletions packages/image_picker/ios/Classes/ImagePickerPlugin.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Expand Down Expand Up @@ -130,17 +129,6 @@ - (void)imagePickerController:(UIImagePickerController *)picker
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
[_imagePickerController dismissViewControllerAnimated:YES completion:nil];
if (image == nil) {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
image = [self normalizedImage:image];

NSNumber *maxWidth = [_arguments objectForKey:@"maxWidth"];
NSNumber *maxHeight = [_arguments objectForKey:@"maxHeight"];

if (maxWidth != (id)[NSNull null] || maxHeight != (id)[NSNull null]) {
image = [self scaledImage:image maxWidth:maxWidth maxHeight:maxHeight];
}

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.

NSData *data = [NSData dataWithContentsOfURL:videoURL];
Expand All @@ -157,6 +145,18 @@ - (void)imagePickerController:(UIImagePickerController *)picker
details:nil]);
}
} else {
if (image == nil) {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
image = [self normalizedImage:image];

NSNumber *maxWidth = [_arguments objectForKey:@"maxWidth"];
NSNumber *maxHeight = [_arguments objectForKey:@"maxHeight"];

if (maxWidth != (id)[NSNull null] || maxHeight != (id)[NSNull null]) {
image = [self scaledImage:image maxWidth:maxWidth maxHeight:maxHeight];
}

NSData *data = UIImageJPEGRepresentation(image, 1.0);
NSString *guid = [[NSProcessInfo processInfo] globallyUniqueString];
NSString *tmpFile = [NSString stringWithFormat:@"image_picker_%@.jpg", guid];
Expand Down
20 changes: 4 additions & 16 deletions packages/image_picker/lib/image_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class ImagePicker {
assert(source != null);

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

if (maxHeight != null && maxHeight < 0) {
throw new ArgumentError.value(maxHeight, 'maxHeight can\'t be negative');
throw new ArgumentError.value(maxHeight, 'maxHeight cannot be negative');
}

final String path = await _channel.invokeMethod(
Expand All @@ -53,32 +53,20 @@ class ImagePicker {
},
);

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

static Future<File> pickVideo({
@required ImageSource source,
double maxWidth,
double maxHeight,
}) async {
assert(source != null);

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

if (maxHeight != null && maxHeight < 0) {
throw new ArgumentError.value(maxHeight, 'maxHeight can\'t be negative');
}

final String path = await _channel.invokeMethod(
'pickVideo',
<String, dynamic>{
'source': source.index,
'maxWidth': maxWidth,
'maxHeight': maxHeight,
},
);
return path != null ? new File(path) : null;
return path == null ? null : new File(path);
}
}