minor improvements
This commit is contained in:
parent
7b295b7d5c
commit
e4741f5942
|
@ -8,7 +8,6 @@
|
|||
|
||||
/* Begin PBXBuildFile section */
|
||||
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
|
||||
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
|
||||
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
|
||||
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
|
||||
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
|
@ -42,7 +41,6 @@
|
|||
/* Begin PBXFileReference section */
|
||||
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
|
||||
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
|
||||
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
|
||||
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
|
||||
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
|
||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
|
||||
|
@ -77,7 +75,6 @@
|
|||
9740EEB11CF90186004384FC /* Flutter */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
|
||||
3B80C3931E831B6300D905FE /* App.framework */,
|
||||
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
|
||||
9740EEBA1CF902C7004384FC /* Flutter.framework */,
|
||||
|
@ -214,7 +211,6 @@
|
|||
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
|
||||
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
|
||||
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
|
||||
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
|
||||
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
|
@ -29,7 +29,10 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
|
|||
void _openFileExplorer() async {
|
||||
if (_pickingType != FileType.CUSTOM || _hasValidMime) {
|
||||
try {
|
||||
if (_multiPick) {
|
||||
if (_pickingType == FileType.DIRECTORY_ONLY) {
|
||||
_path = await FilePicker.getDirectoryPath();
|
||||
print("PATH: " + _path);
|
||||
} else if (_multiPick) {
|
||||
_path = null;
|
||||
_paths = await FilePicker.getMultiFilePath(fileExtension: _extension);
|
||||
} else {
|
||||
|
@ -89,6 +92,10 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
|
|||
child: new Text('CUSTOM FORMAT'),
|
||||
value: FileType.CUSTOM,
|
||||
),
|
||||
new DropdownMenuItem(
|
||||
child: new Text('DIRECTORY ONLY'),
|
||||
value: FileType.DIRECTORY_ONLY,
|
||||
),
|
||||
],
|
||||
onChanged: (value) => setState(() {
|
||||
_pickingType = value;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
@property (nonatomic) FlutterResult result;
|
||||
@property (nonatomic) UIViewController *viewController;
|
||||
@property (nonatomic) UIImagePickerController *galleryPickerController;
|
||||
@property (nonatomic) UIDocumentPickerViewController *pickerController;
|
||||
@property (nonatomic) UIDocumentPickerViewController *documentPickerController;
|
||||
@property (nonatomic) UIDocumentInteractionController *interactionController;
|
||||
@property (nonatomic) MPMediaPickerController *audioPickerController;
|
||||
@property (nonatomic) NSString * fileType;
|
||||
|
@ -37,10 +37,11 @@
|
|||
|
||||
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
||||
if (_result) {
|
||||
_result([FlutterError errorWithCode:@"multiple_request"
|
||||
result([FlutterError errorWithCode:@"multiple_request"
|
||||
message:@"Cancelled by a second request"
|
||||
details:nil]);
|
||||
_result = nil;
|
||||
return;
|
||||
}
|
||||
|
||||
_result = result;
|
||||
|
@ -56,7 +57,6 @@
|
|||
[self resolvePickImage];
|
||||
} else {
|
||||
self.fileType = [FileUtils resolveType:call.method];
|
||||
|
||||
if(self.fileType == nil){
|
||||
result(FlutterMethodNotImplemented);
|
||||
} else {
|
||||
|
@ -70,20 +70,27 @@
|
|||
|
||||
- (void)resolvePickDocumentWithMultipleSelection:(BOOL)allowsMultipleSelection {
|
||||
|
||||
self.pickerController = [[UIDocumentPickerViewController alloc]
|
||||
@try{
|
||||
self.documentPickerController = [[UIDocumentPickerViewController alloc]
|
||||
initWithDocumentTypes:@[self.fileType]
|
||||
inMode:UIDocumentPickerModeImport];
|
||||
} @catch (NSException * e) {
|
||||
Log(@"Can't use documents fie picker. Probably due to iOS version being below 11.0 and not having the iCloud entitlement. If so, just make sure to enable it for your app in Xcode. Exception was: %@", e);
|
||||
_result = nil;
|
||||
return;
|
||||
}
|
||||
|
||||
if (@available(iOS 11.0, *)) {
|
||||
self.pickerController.allowsMultipleSelection = allowsMultipleSelection;
|
||||
self.documentPickerController.allowsMultipleSelection = allowsMultipleSelection;
|
||||
} else if(allowsMultipleSelection) {
|
||||
Log(@"Multiple file selection is only supported on iOS 11 and above. Single selection will be used.");
|
||||
}
|
||||
|
||||
self.pickerController.delegate = self;
|
||||
self.pickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
|
||||
self.documentPickerController.delegate = self;
|
||||
self.documentPickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
|
||||
self.galleryPickerController.allowsEditing = NO;
|
||||
[_viewController presentViewController:self.pickerController animated:YES completion:nil];
|
||||
|
||||
[_viewController presentViewController:self.documentPickerController animated:YES completion:nil];
|
||||
}
|
||||
|
||||
- (void) resolvePickImage {
|
||||
|
@ -124,7 +131,7 @@
|
|||
- (void)documentPicker:(UIDocumentPickerViewController *)controller
|
||||
didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
|
||||
|
||||
[self.pickerController dismissViewControllerAnimated:YES completion:nil];
|
||||
[self.documentPickerController dismissViewControllerAnimated:YES completion:nil];
|
||||
NSArray * result = [FileUtils resolvePath:urls];
|
||||
|
||||
if([result count] > 1) {
|
||||
|
@ -132,6 +139,7 @@ didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
|
|||
} else {
|
||||
_result([result objectAtIndex:0]);
|
||||
}
|
||||
_result = nil;
|
||||
|
||||
}
|
||||
|
||||
|
@ -159,9 +167,12 @@ didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
|
|||
_result([FlutterError errorWithCode:@"file_picker_error"
|
||||
message:@"Temporary file could not be created"
|
||||
details:nil]);
|
||||
_result = nil;
|
||||
return;
|
||||
}
|
||||
|
||||
_result([pickedVideoUrl != nil ? pickedVideoUrl : pickedImageUrl path]);
|
||||
_result = nil;
|
||||
}
|
||||
|
||||
|
||||
|
@ -174,6 +185,7 @@ didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
|
|||
Log(@"Couldn't retrieve the audio file path, either is not locally downloaded or the file DRM protected.");
|
||||
}
|
||||
_result([url absoluteString]);
|
||||
_result = nil;
|
||||
}
|
||||
|
||||
#pragma mark - Actions canceled
|
||||
|
|
|
@ -4,13 +4,7 @@ import 'package:flutter/services.dart';
|
|||
|
||||
String _kCustomType = '__CUSTOM_';
|
||||
|
||||
enum FileType {
|
||||
ANY,
|
||||
IMAGE,
|
||||
VIDEO,
|
||||
AUDIO,
|
||||
CUSTOM,
|
||||
}
|
||||
enum FileType { ANY, IMAGE, VIDEO, AUDIO, CUSTOM, DIRECTORY_ONLY }
|
||||
|
||||
class FilePicker {
|
||||
static const MethodChannel _channel = const MethodChannel('file_picker');
|
||||
|
@ -29,11 +23,24 @@ class FilePicker {
|
|||
}
|
||||
return result;
|
||||
} on PlatformException catch (e) {
|
||||
print("[$_tag] Platform exception: " + e.toString());
|
||||
print('[$_tag] Platform exception: ' + e.toString());
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
print(
|
||||
"[$_tag] Unsupported operation. This probably have happened because [${type.split('_').last}] is an unsupported file type. You may want to try FileType.ALL instead.");
|
||||
'[$_tag] Unsupported operation. This probably have happened because [${type.split('_').last}] is an unsupported file type. You may want to try FileType.ALL instead.');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static Future<String> getDirectoryPath() async {
|
||||
try {
|
||||
final String result = await _channel.invokeMethod("getDirectoryPath");
|
||||
return result;
|
||||
} on PlatformException catch (e) {
|
||||
print('[$_tag] Platform exception: ' + e.toString());
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
print('[$_tag] Unsupported operation.');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue