简体   繁体   中英

What is app_flutter directory in dart/flutter

I'm working on a flutter application, and I want to write to a JSON file.

My JSON file is in the 'assets/' folder that I created and added to pubspec.yaml. I can get the data using:

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

I went through here to get the path to the file: https://docs.flutter.dev/cookbook/persistence/reading-writing-files ,

Like this:

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');
}

But when I try to access the file, I get this error:

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

Do you know why?

Thank you!

You can navigate to this path with root privileges.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM