簡體   English   中英

dart/flutter 中的 app_flutter 目錄是什么

[英]What is app_flutter directory in dart/flutter

我正在開發 flutter 應用程序,我想寫入 JSON 文件。

我的 JSON 文件位於我創建並添加到 pubspec.yaml 的“assets/”文件夾中。 我可以使用以下方法獲取數據:

final String res2 = await rootBundle.loadString("assets/profile.json");

我通過這里獲取文件的路徑: https://docs.flutter.dev/cookbook/persistence/reading-writing-files

像這樣:

Future<File> get _localFile async {
  final path = await _localPath;
  return File('$path/assets/profile.json');
}

Future<String> get _localPath async {
  final directory = await getApplicationDocumentsDirectory();
  return directory.path;
}

Future<File> writeJSON(newDatas) async {
  final file = await _localFile;
  // Write the file
  return file.writeAsString('$newDatas');
}

但是當我嘗試訪問該文件時,我收到此錯誤:

Cannot open file, path = '/data/user/0/com.example.myapp/app_flutter/assets/profile.json'

你知道為什么嗎?

謝謝!

您可以使用 root 權限導航到此路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM