I am building and flutter app which need to create it's own folder or directory in device but i am unable to do that here is my code to create that folder
Future <io.Directory> get getExternalVisibleDir async{
try {
if (await io.Directory('/storage/emulated/0/myFolder').exists()) {
final externalDir = io.Directory('/storage/emulated/0/myFolder');
return externalDir;
} else {
await io.Directory('/storage/emulated/0/myFolder').create(
recursive: true);
final externalDir = io.Directory('/storage/emulated/0/myFolder');
return externalDir;
}
}catch(e){
print("Unable to create directory");
}
}
here is my menifest permissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:label="data_encryption"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:requestLegacyExternalStorage="true"
>
and here is my permission handler
requestStoragePermission() async{
if(!await Permission.storage.isGranted){
PermissionStatus result = await Permission.storage.request();
if(result.isGranted){
setState(() {
_isgranted =true;
});
}else{
_isgranted=false;
}
}
}