pickFilesFromDevice method
Returns a list of File objects selected from device using file picker.
If allowMultiple
is true, multiple files can be selected.
fileType
enum specifies the type of file to be picked (e.g., image, video, audio, media, any).
allowedExtensions
can be specified to filter the file types that can be selected.
Returns an empty list if no files are selected.
Example usage:
List<File?> files = await RhUtils.instance.pickFilesFromDevice(
allowMultiple: true,
fileType: FileType.custom,
allowedExtensions: ['jpg', 'jpeg', 'png'],
);
Implementation
Future<List<File?>> pickFilesFromDevice({
required bool allowMultiple,
required FileType fileType,
required List<String> allowedExtensions,
}) async {
List<File?> files = [];
FilePickerResult? result = await FilePicker.platform.pickFiles(
allowMultiple: allowMultiple,
type: fileType,
allowedExtensions: allowedExtensions,
);
if (result != null) {
files = result.paths
.map((path) => (path == null) ? null : File(path))
.toList();
}
return files;
}