FOR ME THIS WORKS
permission_handler
But first set the permissions right in your Android Manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
THIS IS BY FAR THE BEST SOLUTION:
for both IOS and Android (BEST)
Future<String> createFolder(String cow) async {
final dir = Directory((Platform.isAndroid
? await getExternalStorageDirectory() //FOR ANDROID
: await getApplicationSupportDirectory() //FOR IOS
)!
.path + '/$cow');
var status = await Permission.storage.status;
if (!status.isGranted) {
await Permission.storage.request();
}
if ((await dir.exists())) {
return dir.path;
} else {
dir.create();
return dir.path;
}
}
NOTE:
If you name your createFolder(".folder") that folder will be hidden.
If you create a .nomedia file in your folder, other apps won't be able to scan your folder.
NOTE II:
As of Android 11 and above, apps have been banned from creating custom folders using "storage/emulated/0/$folderName"
The solution below is OBSOLETE as of Android 11 and above:
Reference
Future<String> createFolder(String cow) async {
final folderName = cow;
final path = Directory("storage/emulated/0/$folderName");
var status = await Permission.storage.status;
if (!status.isGranted) {
await Permission.storage.request();
}
if ((await path.exists())) {
return path.path;
} else {
path.create();
return path.path;
}
}