getAppDirectory static method

Future<Directory> getAppDirectory({
  1. String subDir = 'log',
})

android /android/data/xxx.xxx.package/files/log(subDir)

Implementation

static Future<Directory> getAppDirectory({String subDir = 'log'}) async {
  final directory = Platform.isIOS ? await getApplicationDocumentsDirectory() : await getExternalStorageDirectory();
  final file = Directory('${directory!.path}/$subDir');
  final bool exists = file.existsSync();
  if (exists == false) {
    if (!file.existsSync()) {
      file.createSync(recursive: true);
    }
  }
  return file;
}