Skip to content

Commit e9cd1fc

Browse files
zhongwuzwEgor
authored andcommitted
[image_picker] Fixes crash when an image in the gallery is tapped mor… (flutter#2668)
1 parent 96b6a02 commit e9cd1fc

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-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.6
2+
3+
* Fixes crash when an image in the gallery is tapped more than once.
4+
15
## 0.6.5+1
26

37
* Fix CocoaPods podspec lint warnings.

packages/image_picker/ios/Classes/FLTImagePickerPlugin.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ - (void)imagePickerController:(UIImagePickerController *)picker
279279
}
280280
self.result(videoURL.path);
281281
self.result = nil;
282-
282+
_arguments = nil;
283283
} else {
284284
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
285285
if (image == nil) {
@@ -322,7 +322,6 @@ - (void)imagePickerController:(UIImagePickerController *)picker
322322
}];
323323
}
324324
}
325-
_arguments = nil;
326325
}
327326

328327
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
@@ -357,6 +356,9 @@ - (void)saveImageWithPickerInfo:(NSDictionary *)info
357356
}
358357

359358
- (void)handleSavedPath:(NSString *)path {
359+
if (!self.result) {
360+
return;
361+
}
360362
if (path) {
361363
self.result(path);
362364
} else {
@@ -365,6 +367,7 @@ - (void)handleSavedPath:(NSString *)path {
365367
details:nil]);
366368
}
367369
self.result = nil;
370+
_arguments = nil;
368371
}
369372

370373
@end

packages/image_picker/ios/Tests/ImagePickerPluginTests.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
@import image_picker;
88
@import XCTest;
99

10+
@interface FLTImagePickerPlugin (Test)
11+
@property(copy, nonatomic) FlutterResult result;
12+
- (void)handleSavedPath:(NSString *)path;
13+
@end
14+
1015
@interface ImagePickerPluginTests : XCTestCase
1116
@end
1217

@@ -90,4 +95,20 @@ - (void)testPickingVideoWithDuration {
9095
XCTAssertEqual([plugin getImagePickerController].videoMaximumDuration, 95);
9196
}
9297

98+
- (void)testPluginPickImageSelectMultipleTimes {
99+
FLTImagePickerPlugin *plugin =
100+
[[FLTImagePickerPlugin alloc] initWithViewController:[UIViewController new]];
101+
FlutterMethodCall *call =
102+
[FlutterMethodCall methodCallWithMethodName:@"pickImage"
103+
arguments:@{@"source" : @(0), @"cameraDevice" : @(0)}];
104+
[plugin handleMethodCall:call
105+
result:^(id _Nullable r){
106+
}];
107+
plugin.result = ^(id result) {
108+
109+
};
110+
[plugin handleSavedPath:@"test"];
111+
[plugin handleSavedPath:@"test"];
112+
}
113+
93114
@end

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.5+1
5+
version: 0.6.6
66

77
flutter:
88
plugin:

0 commit comments

Comments
 (0)