I am receiving an error as Unhandled Exception: FileSystemException: Creation failed, path = 'Directory: '' (OS Error: Read-only file system, errno = 30)
when I am trying to save a xlsx file.
Code:
class ExportPasswords {
static exportUserEntries(List entries) async {
final _psd = PasswordDecrypter();
final _secureStorage = FlutterSecureStorage();
//creating the xlsx
var excel = Excel.createExcel();
var fileBytes = excel.save();
Sheet sheetObject = excel['pssswd_export'];
CellStyle cellStyle = CellStyle(
backgroundColorHex: "#1AFF1A",
fontFamily: getFontFamily(FontFamily.Calibri));
cellStyle.underline = Underline.Single;
for (var entry in entries) {
final _username = entry['data']['username'];
final _name = entry['data']['name'];
final _url = entry['data']['url'];
final _hashedPassword = entry['data']['password'];
final _randForKeyToStore = entry['data']['randForKeyToStore'];
final _randForIV = entry['data']['randForIV'];
final _masterPassword = await _secureStorage.read(key: 'masterPassword');
final _decryptedEntryPassword = await _psd.getDecryptedPassword(
_hashedPassword, _randForKeyToStore, _randForIV, _masterPassword);
sheetObject.appendRow([_name, _username, _decryptedEntryPassword, _url]);
}
PermissionStatus permissionResult =
await SimplePermissions.requestPermission(
Permission.WriteExternalStorage);
if (permissionResult == PermissionStatus.authorized) {
Directory directory = await getApplicationDocumentsDirectory();
// print(directory);
new Directory(directory.path '/').create(recursive: true).then((dir) {
print(dir);
File(join('$dir/pssswd_export'))
..createSync(recursive: true)
..writeAsBytesSync(fileBytes!);
});
}
}
}
I have given the permission of WRITE_EXTERNAL_STORAGE.
I/SimplePermission( 7685): Requesting permission : android.permission.WRITE_EXTERNAL_STORAGE
I/SimplePermission( 7685): Requesting permission status : 3
In the error it is displayed as Directory : ''
, but when I am printing the directory value it is showing the path
I/flutter ( 7685): Directory: '/data/user/0/com.palsoham.pssswd.pssswd/app_flutter/'
CodePudding user response:
Please try changing your path in File
function from '$dir/pssswd_export'
to dir.path /pssswd_export'
.