prepareJidoujishoDirectory method

Future<Directory> prepareJidoujishoDirectory()

Return the app external directory found in the public DCIM directory. This path also initialises the folder if it does not exist, and includes a .nomedia file within the folder.

Implementation

Future<Directory> prepareJidoujishoDirectory() async {
  String publicDirectory =
      await ExternalPath.getExternalStoragePublicDirectory(
          ExternalPath.DIRECTORY_DCIM);
  try {
    String directoryPath = path.join(publicDirectory, 'jidoujisho');
    String noMediaFilePath =
        path.join(publicDirectory, 'jidoujisho', '.nomedia');

    Directory jidoujishoDirectory = Directory(directoryPath);
    File noMediaFile = File(noMediaFilePath);

    if (!jidoujishoDirectory.existsSync()) {
      jidoujishoDirectory.createSync(recursive: true);
    }
    if (!noMediaFile.existsSync()) {
      noMediaFile.createSync();
    }

    return jidoujishoDirectory;
  } catch (e) {
    debugPrint('Failed to create directory in DCIM.');
    return prepareFallbackJidoujishoDirectory();
  }
}