getDocumentPath static method

Future<String> getDocumentPath()

获取应用程序文档目录路径

返回文档目录的路径字符串,如果获取失败则返回空字符串

Implementation

static Future<String> getDocumentPath() async {
  if (kIsWeb) {
    return "";
  }
  try {
    if (Platform.isAndroid) {
      final directory = await getExternalStorageDirectory();
      return directory?.path ?? '';
    } else if (Platform.isIOS) {
      final directory = await getApplicationDocumentsDirectory();
      return directory.path;
    }
    return '';
  } catch (e) {
    developer.log('获取文档路径失败: $e');
    return '';
  }
}