How can I save and create files in internal device storage in flutter? When I create file with getExternalStorageDirectory(), the file hasn't appeared in internal storage.
String fileExtension = name!.split('.').last;
String fileName =
name!.replaceAll('.${fileExtension}', '');
String? localPath = await _findLocalPath();
String completePath = '${localPath}/${fileName}.${fileExtension}';
logger.e(completePath);
io.File file = io.File(completePath);
await file.writeAsBytes(dataStore);
file.create();
Future<String?> _findLocalPath() async {
String? externalStorageDirPath;
if (io.Platform.isAndroid) {
final io.Directory? directory = await getExternalStorageDirectory();
externalStorageDirPath = directory!.path;
} else if (io.Platform.isIOS) {
externalStorageDirPath =
(await getApplicationDocumentsDirectory()).absolute.path;
}
final io.Directory savedDir = io.Directory(externalStorageDirPath!);
bool hasExisted = await savedDir.exists();
logger.e(hasExisted);
if (!hasExisted) {
logger.e('Create Folder');
savedDir.create();
}
return externalStorageDirPath;
}
Can anyone help me?