1
I am generating a PDF file and I want to save it in the "downloads" of mobile device, I am using "downloads_path_provider: 0.1.0" for this but when I save I have the following error:
[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FileSystemException: Cannot open file, path = 'Directory: '/storage/emulated/0/Download'/example.pdf' (OS Error: No such file or directory, errno = 2)
the code itself is quite simple because I’m still starting:
teste() async {
// Directory documentDirectory = await getApplicationDocumentsDirectory();
// String documentPath = documentDirectory.path;
Directory downloadsDirectory;
final doc = pw.Document();
try {
downloadsDirectory = await DownloadsPathProvider.downloadsDirectory;
} on PlatformException {
print('Could not get the downloads directory');
}
print(downloadsDirectory);
doc.addPage(
pw.Page(
build: (pw.Context context) => pw.Center(
child: pw.Text('batata'),
),
),
);
File file = File("$downloadsDirectory/example.pdf");
file.writeAsBytesSync(doc.save());
}
I thought it might be because I use an emulator but I had the same problem on the real device.