pickFile function

Future<File?> pickFile(
  1. {List<String>? allowedExtensions,
  2. List<String>? allowedMimeTypes,
  3. FilePickerListener? listener}
)

Pick a file using the native file explorer.

The files available for selection can be restricted by specifying a list of allowed file extensions or a list of allowed MIME types or a combination of the two.

If the user selects a large file or if the selected file is stored on a virtual file system such as OneDrive or iCloud, copying the file to a temporary location might take a while. To inform the user about the file being copied, e.g. by displaying a progress dialog, a listener can be specified that informs about the copy status of the file.

Implementation

Future<File?> pickFile({
  List<String>? allowedExtensions,
  List<String>? allowedMimeTypes,
  FilePickerListener? listener,
}) async {
  final completer = Completer<File?>();
  _jobController.add(_Job(
    completer: completer,
    allowedExtensions: allowedExtensions,
    allowedMimeTypes: allowedMimeTypes,
    listener: listener,
  ));
  if (!_workerStarted) {
    _worker();
    _workerStarted = true;
  }
  return completer.future;
}