I have a PDF file of about 800 pages in my app asset folder, I am trying to view this PDF file using the flutter_pdfview package but it gives me the above error.
Tried lots of methods but didn't work for me
AndroidMenifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:requestLegacyExternalStorage="true"
Method to get and display a PDF file:
Future<File> fromAsset(String asset, String filename) async {
Completer<File> completer = Completer();
try {
var dir = await getApplicationDocumentsDirectory();
File file = File("${dir.path}/$filename");
var data = await rootBundle.load(asset);
var bytes = data.buffer.asUint8List();
await file.writeAsBytes(bytes, flush: true);
completer.complete(file);
} catch (e) {
throw Exception('Error parsing asset file!');
}
return completer.future;
}
Requesting storage permission:
Future<void> checkStoragePermission() async {
final status = await Permission.storage.request();
if (status.isGranted) {
setState(() {
isPermitted = true;
});
fromAsset('assets/pdf/book.pdf', 'myBook.pdf').then((f) {
setState(() {
pathPDF = f.path;
});
});
}else{
isPermitted=false;
}
}
I have a PDF file of about 800 pages in my app asset folder, I am trying to view this PDF file using the flutter_pdfview package but it gives me the error:
- java.io.FileNotFoundException: open failed: EACCES (Permission denied)