diff --git a/CHANGELOG.md b/CHANGELOG.md index 207f3583..6d76dbaf 100644 --- a/CHANGELOG.md +++ b/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. diff --git a/ios/Classes/FilePickerPlugin.m b/ios/Classes/FilePickerPlugin.m index 8670ffbd..c0f3e80c 100644 --- a/ios/Classes/FilePickerPlugin.m +++ b/ios/Classes/FilePickerPlugin.m @@ -417,12 +417,15 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray_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; } @@ -488,6 +491,14 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray_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]; }); } diff --git a/lib/src/file_picker.dart b/lib/src/file_picker.dart index 44911e7f..f5bc99eb 100644 --- a/lib/src/file_picker.dart +++ b/lib/src/file_picker.dart @@ -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; @@ -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) { diff --git a/pubspec.yaml b/pubspec.yaml index c2cf4899..380e1a4e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: