getExternalStorageFile method

Future<File?> getExternalStorageFile({
  1. required String fileName,
  2. String? filePath,
})

外部存储目录,Android 特有,删除应用不会删除该目录 应用程序可以访问顶层存储的目录的路径。在发出这个函数调用之前,应该确定当前操作系统,因为这个功能只在Android上可用。 在iOS上,这个函数抛出一个UnsupportedError,因为它不可能访问应用程序的沙箱之外。 在Android上,它使用“getExternalStorageDirectory”API。

Implementation

Future<File?> getExternalStorageFile({required String fileName, String? filePath}) async {
  if (!Platform.isAndroid) {
    return null;
  }
  try {
    final extDir = await getExternalStorageDirectory();
    if (extDir == null) {
      return null;
    }
    return _getFile(extDir, filePath, fileName);
  } catch (e) {
    logger.e(tag: TAG, e);
    return null;
  }
}