pickFile method
Future<File?>
pickFile(
{ - List<String>? allowedExtensions,
- FileType type = fp.FileType.any,
- bool allowCompression = true,
- bool allowMultiple = false,
- String? dialogTitle,
})
Implementation
Future<File?> pickFile({
List<String>? allowedExtensions,
fp.FileType type = fp.FileType.any,
bool allowCompression = true,
bool allowMultiple = false,
String? dialogTitle,
}) async {
bool hasPermission = await _checkStoragePermission();
if (!hasPermission) return null;
try {
final result = await fp.FilePicker.platform.pickFiles(
type: allowedExtensions != null ? fp.FileType.custom : type,
allowedExtensions: allowedExtensions,
allowCompression: allowCompression,
allowMultiple: allowMultiple,
dialogTitle: dialogTitle,
withData: false,
withReadStream: true,
);
if (result != null && result.files.isNotEmpty) {
final path = result.files.first.path;
if (path != null) {
return File(path);
}
}
} catch (e) {
print('Error picking file: $e');
}
return null;
}