Skip to content

Commit

Permalink
Improves error handling when device has no space (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpruivo committed Nov 19, 2021
1 parent 240c83f commit 13bc9b4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
@@ -1,4 +1,9 @@
## 4.1.3
## 4.2.4

##### iOS
Improves error handling when device can't fetch files due to low storage space ([#885](https://github.com/miguelpruivo/flutter_file_picker/issues/885)).

## 4.2.3

##### iOS
Fixed an issue that was creating a crash when media in PHPickerViewController in iOs was tapped several times very fast, we check that _result is not empty to avoid the crash. No Github issue created.
Expand Down
13 changes: 12 additions & 1 deletion ios/Classes/FilePickerPlugin.m
Expand Up @@ -417,12 +417,15 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPicke
self->_eventSink([NSNumber numberWithBool:YES]);
}

__block NSError * blockError;

for (PHPickerResult *result in results) {
dispatch_group_enter(_group);
[result.itemProvider loadFileRepresentationForTypeIdentifier:@"public.item" completionHandler:^(NSURL * _Nullable url, NSError * _Nullable error) {

if(url == nil) {
Log("Could not load the picked given file: %@", error);
blockError = error;
Log("Could not load the picked given file: %@", blockError);
dispatch_group_leave(self->_group);
return;
}
Expand Down Expand Up @@ -488,6 +491,14 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPicke
if(self->_eventSink != nil) {
self->_eventSink([NSNumber numberWithBool:NO]);
}

if(blockError) {
self->_result([FlutterError errorWithCode:@"file_picker_error"
message:@"Temporary file could not be created"
details:blockError.description]);
self->_result = nil;
return;
}
[self handleResult:urls];
});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/file_picker.dart
Expand Up @@ -38,7 +38,7 @@ abstract class FilePicker extends PlatformInterface {

static final Object _token = Object();

static late FilePicker _instance = _setPlatform();
static late FilePicker _instance = FilePicker._setPlatform();

static FilePicker get platform => _instance;

Expand All @@ -47,7 +47,7 @@ abstract class FilePicker extends PlatformInterface {
_instance = instance;
}

static FilePicker _setPlatform() {
factory FilePicker._setPlatform() {
if (Platform.isAndroid || Platform.isIOS) {
return FilePickerIO();
} else if (Platform.isLinux) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Expand Up @@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
repository: https://github.com/miguelpruivo/flutter_file_picker
issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues
version: 4.2.3
version: 4.2.4

dependencies:
flutter:
Expand Down

0 comments on commit 13bc9b4

Please sign in to comment.