createFolderInAppDocDir static method
This method creates a new folder with the given folderName in the application documents directory and returns its path.
Implementation
static Future<String> createFolderInAppDocDir(String folderName) async {
//Get this App Document Directory
final Directory appDocDir = await getApplicationDocumentsDirectory();
String finalPathTargetFolder = path.join(appDocDir.path, folderName);
//App Document Directory + folder name
final Directory appDocDirFolder =
Directory(finalPathTargetFolder);
if (await appDocDirFolder.exists()) {
//if folder already exists return path
return appDocDirFolder.path;
} else {
//if folder not exists create folder and then return its path
final Directory appDocDirNewFolder =
await appDocDirFolder.create(recursive: true);
return appDocDirNewFolder.path;
}
}