importFromStorage static method

Future<FilePickerCross> importFromStorage({
  1. FileTypeCross type = FileTypeCross.any,
  2. String fileExtension = '',
})

Shows a dialog for selecting a file from your device's internal storage. If thee selected file is a Null byte, a NullThrownError is thrown. If the file selection was canceled by the user, a FileSelectionCanceledError is thrown.

Implementation

static Future<FilePickerCross> importFromStorage({
  FileTypeCross type = FileTypeCross.any,
  String fileExtension = '',
}) async {
  try {
    final Map<String, Uint8List> file = await selectSingleFileAsBytes(
      type: type,
      fileExtension: fileExtension,
    );

    String _path = file.keys.toList()[0];
    Uint8List? _bytes = file[_path];

    if (_bytes == null) {
      throw (NullThrownError());
    }
    return FilePickerCross(_bytes,
        path: _path, fileExtension: fileExtension, type: type);
  } catch (e) {
    throw FileSelectionCanceledError(e);
  }
}