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

Commit bf84104

Browse files
committed
[image_picker] fix bug, sometimes double click cancel button will crash
1 parent 8819b21 commit bf84104

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

packages/image_picker/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.4+1
2+
3+
* Fix a bug, sometimes double click cancel button will crash.
4+
15
## 0.6.4
26

37
* Add a new parameter to select preferred camera device.

packages/image_picker/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
14791121244188AC0028A572 /* ImagePickerPluginTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 14791120244188AC0028A572 /* ImagePickerPluginTests.m */; };
1011
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
1112
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
1213
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -55,6 +56,7 @@
5556
/* End PBXCopyFilesBuildPhase section */
5657

5758
/* Begin PBXFileReference section */
59+
14791120244188AC0028A572 /* ImagePickerPluginTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ImagePickerPluginTests.m; path = ../../../ios/Tests/ImagePickerPluginTests.m; sourceTree = "<group>"; };
5860
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
5961
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
6062
5A9D31B91557877A0E8EF3E7 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
@@ -116,6 +118,7 @@
116118
68F4B463228B3AB500C25614 /* PhotoAssetUtilTests.m */,
117119
F78AF3172342D9D7008449C7 /* ImagePickerTestImages.h */,
118120
F78AF3182342D9D7008449C7 /* ImagePickerTestImages.m */,
121+
14791120244188AC0028A572 /* ImagePickerPluginTests.m */,
119122
);
120123
path = image_picker_exampleTests;
121124
sourceTree = "<group>";
@@ -390,6 +393,7 @@
390393
9FC8F0EE229FB90B00C8D58F /* ImageUtilTests.m in Sources */,
391394
F78AF3192342D9D7008449C7 /* ImagePickerTestImages.m in Sources */,
392395
680049262280D736006DD6AB /* MetaDataUtilTests.m in Sources */,
396+
14791121244188AC0028A572 /* ImagePickerPluginTests.m in Sources */,
393397
68F4B464228B3AB500C25614 /* PhotoAssetUtilTests.m in Sources */,
394398
);
395399
runOnlyForDeploymentPostprocessing = 0;

packages/image_picker/ios/Classes/FLTImagePickerPlugin.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,10 @@ - (void)imagePickerController:(UIImagePickerController *)picker
323323

324324
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
325325
[_imagePickerController dismissViewControllerAnimated:YES completion:nil];
326+
if (!self.result) {
327+
return;
328+
}
326329
self.result(nil);
327-
328330
self.result = nil;
329331
_arguments = nil;
330332
}

packages/image_picker/ios/Tests/ImagePickerPluginTests.m

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,30 @@ - (void)testPluginPickVideoDeviceBack {
6161
UIImagePickerControllerCameraDeviceRear);
6262
}
6363

64+
- (void)testPluginPickImageDeviceCancel {
65+
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
66+
return;
67+
}
68+
FLTImagePickerPlugin *plugin =
69+
[[FLTImagePickerPlugin alloc] initWithViewController:[UIViewController new]];
70+
FlutterMethodCall *call =
71+
[FlutterMethodCall methodCallWithMethodName:@"pickImage"
72+
arguments:@{@"source" : @(0), @"cameraDevice" : @(1)}];
73+
[plugin handleMethodCall:call
74+
result:^(id _Nullable r){
75+
}];
76+
// todo test imagePickerControllerDidCancel when result is nil
77+
78+
}
79+
6480
- (void)testPluginPickVideoDeviceFront {
6581
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
6682
return;
6783
}
6884
FLTImagePickerPlugin *plugin =
6985
[[FLTImagePickerPlugin alloc] initWithViewController:[UIViewController new]];
7086
FlutterMethodCall *call =
71-
[FlutterMethodCall methodCallWithMethodName:@"pickVideo"
87+
[FlutterMethodCall methodCallWithMethodName:@"pickImage"
7288
arguments:@{@"source" : @(0), @"cameraDevice" : @(1)}];
7389
[plugin handleMethodCall:call
7490
result:^(id _Nullable r){

packages/image_picker/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: image_picker
22
description: Flutter plugin for selecting images from the Android and iOS image
33
library, and taking new pictures with the camera.
44
homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker
5-
version: 0.6.4
5+
version: 0.6.4+1
66

77
flutter:
88
plugin:

0 commit comments

Comments
 (0)