saveDownload function
Implementation
Future<void> saveDownload(String name, Stream<List<int>> bytes) async {
if (_savePicker == null) {
await saveDownloadInMemory(name, bytes);
return;
}
// Called directly from the user gesture, before starting the network stream.
final handle = await _pickFile(_PickerOptions(suggestedName: name)).toDart;
final writer = await handle.createWritable().toDart;
try {
await for (final chunk in bytes) {
await writer.write(Uint8List.fromList(chunk).toJS).toDart;
}
await writer.close().toDart;
} catch (_) {
await writer.abort().toDart;
rethrow;
}
}