filePicker static method
dynamic
filePicker({})
function file picker for pick any file and save to temporary cache directory
Implementation
static filePicker(
{required FileData fileData,
required Function(FileData fileData) onSelected,
Function(String message, int messageCode)? onCancel,
int? maxFileSizeInMb,
List<String> allowedExtensions = const [
Files.pdf,
Files.doc,
Files.docx,
Files.xls,
Files.xlsx,
Files.ppt,
Files.pptx,
Files.png,
Files.jpg,
Files.jpeg
]}) async {
FilePickerResult? result = await FilePicker.platform
.pickFiles(type: FileType.custom, allowedExtensions: allowedExtensions);
if (result != null && result.files.single.path != null) {
if (maxFileSizeInMb != null &&
Files.mb(result.files.single.size) > maxFileSizeInMb) {
dev.log(
"[${Files._mcFPCForSize}] ${Files._fileMoreThanMB(maxFileSizeInMb)}");
if (onCancel != null) {
onCancel(Files._fileMoreThanMB(maxFileSizeInMb), Files._mcFPCForSize);
}
return;
}
FileData fileData = FileData(
hasFile: true,
fileName: result.files.single.name,
filePath: result.files.single.path!,
fileMimeType: Files.getMimeType(result.files.single.path!),
path: result.files.single.path!);
onSelected(fileData);
} else {
dev.log("[${Files._mcFPCForCancel}] ${Files._filePickCancel}");
if (onCancel != null) {
onCancel(Files._filePickCancel, Files._mcFPCForCancel);
}
return;
}
}