getStoragePath static method

Future<String> getStoragePath({
  1. String? fileName,
  2. String? dirName,
})

应用程序可以访问顶层存储的目录的路径 支持Android 不支持iOS fileName 文件名 dirName 文件夹名

Implementation

static Future<String> getStoragePath({
  String? fileName,
  String? dirName,
}) async {
  Directory? _storageDir = await _initStorageDir();
  if (_storageDir == null) {
    return "";
  }
  StringBuffer sb = StringBuffer(_storageDir.path);
  if (dirName != null && dirName.isNotEmpty) {
    sb.write("/$dirName");
    await createDirSync(sb.toString());
  }
  if (fileName != null && fileName.isNotEmpty) {
    sb.write("/$fileName");
  }
  return sb.toString();
}