launchPicker method
Implementation
@override
Future<File?> launchPicker(List<IDetectable>? detectors) async
{
try
{
file_picker.FilePickerResult? result = await file_picker.FilePicker.platform.pickFiles(withReadStream: true, type: (accept == null) || (accept!.isEmpty) ? file_picker.FileType.any : file_picker.FileType.custom, allowedExtensions: accept);
if (result != null)
{
// set file
XFile file = XFile(result.files.single.path!);
String url = "file:${file.path}";
String type = (await S.mimetype(file.path)).toLowerCase();
String name = basename(file.path);
int size = await file.length();
// detect in image
if ((detectors != null) && (type.startsWith("image")))
{
// create detectable image
DetectableImage detectable = DetectableImage.fromFilePath(result.files.single.path!);
// detect
for (var detector in detectors) {
detector.detect(detectable, false);
}
}
// return the file
return File(file, url, name, type, size);
}
}
catch(e)
{
Log().debug('Error Launching File Picker');
}
return null;
}