writeFile method
Writes data to a file previously picked by the user.
Expects a FileInfo.identifier string for identifier
.
The writer
will receive a file in a temporary directory named
fileName
(if not given will be called temp
).
The temporary directory will be deleted when writing is complete.
Implementation
Future<FileInfo> writeFile({
required String identifier,
String fileName = 'temp',
required Future<void> Function(File file) writer,
}) async {
_logger.finest('writeFileWithIdentifier()');
final result =
await _createFileInNewTempDirectory(fileName, (tempFile) async {
await writer(tempFile);
final result = await _channel
.invokeMapMethod<String, String>('writeFileWithIdentifier', {
'identifier': identifier,
'path': tempFile.absolute.path,
});
return result!;
});
return _resultToFileInfo(result);
}