I was following - how to create directory from https://docs.flutter.io/flutter/dart-io/Directory-class.html
new Directory('dir/subdir').create(recursive: true)
// The created directory is returned as a Future.
.then((Directory directory) {
print(directory.path);
});
This is the error I am getting:
FileSystemException: Creation failed, path = 'dir' (OS Error: Read-only file system, errno = 30)
I have enabled Storage(WRITE_EXTERNAL_STORAGE)
permission.
(Android device)
What am I missing?
Got it (Using path_provider plugin to get correct path)
Directory appDocDirectory = await getApplicationDocumentsDirectory();
new Directory(appDocDirectory.path+'/'+'dir').create(recursive: true)
// The created directory is returned as a Future.
.then((Directory directory) {
print('Path of New Dir: '+directory.path);
});
Update : New Flutter plugin permission_handler have taken care below thing so change your plugin to permission_handler
If you are testing in Android Oreo and want to write file in external storage then you need to ask WRITE_EXTERNAL_STORAGE
According to "https://developer.android.com/about/versions/oreo/android-8.0-changes.html#rmp"
If the app targets Android 8.0 (API level 26), the system grants only READ_EXTERNAL_STORAGE at that time; however, if the app later requests WRITE_EXTERNAL_STORAGE, the system immediately grants that privilege without prompting the user.
Permission Plugin ask only READ_EXTERNAL_STORAGE permission by Permission.requestPermissions([PermissionName.Storage])
;
so You need to ask for WRITE_EXTERNAL_STORAGE.
You can use my repo for asking WRITE_EXTERNAL_STORAGE in pubspec.yaml:
permission:
git:
url: https://github.com/kamlesh9070/permission
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With