getApplicationDocumentsDirectory function

Future<Directory> getApplicationDocumentsDirectory()

Path to a directory where the application may place data that is user-generated, or that cannot otherwise be recreated by your application.

Consider using another path, such as getApplicationSupportDirectory, getApplicationCacheDirectory, or getExternalStorageDirectory, if the data is not user-generated.

Example implementations:

  • NSDocumentDirectory on iOS and macOS.
  • The Flutter engine's PathUtils.getDataDirectory API on Android.

Throws a MissingPlatformDirectoryException if the system is unable to provide the directory.

Implementation

Future<Directory> getApplicationDocumentsDirectory() async {
  final String? path = await _platform.getApplicationDocumentsPath();
  if (path == null) {
    throw MissingPlatformDirectoryException(
        'Unable to get application documents directory');
  }
  return Directory(path);
}