saveToPrivateDir method
Saves the file into a subdirectory of the private storage path.
When autoName is true, a UUID-based filename is generated while
preserving the original extension when possible.
Returns the written File.
Example:
final saved = await file.saveToPrivateDir('documents');
print(saved.path);
Implementation
Future<File> saveToPrivateDir(String subDir, {bool autoName = true}) async {
final String fileName;
if (autoName) {
final ext = extension.isNotEmpty ? '.$extension' : '';
final uuid = Uuid().v4();
fileName = '$uuid$ext';
} else {
fileName = filename;
}
final file = File('lib/src/storage/private/$subDir/$fileName');
if (!await file.parent.exists()) {
await file.parent.create(recursive: true);
}
final bytes = await _cachedBytes;
await file.writeAsBytes(bytes);
return file;
}