Open Appvala opened 3 years ago
Same for me, using latest flutter version 2.2.1
I am having the same problem. I am using flutter version 2.2.1
same for me
same for me
I am facing the same issue with flutter v2.2.1
I think the problem is due to the import file in the plugin itself. I don't know for sure but the File class object we are passing is from 'dart:io' but in the plugin, the File which it is expecting is abstract class File.
yes, I saw the problem with the file class too. I added 'as' while importing. My problem is not solved. there is still a problem.
Came across this issue after upgrading to Flutter 2.2.1 and even the same persisted after downgrading it to 2.2.0.
Sol, that worked:
Edited the /flutter/.pub-cache/hosted/pub.dartlang.org/advance_pdf_viewer-2.0.0/lib/src/document.dart
import 'dart:io'; - > import 'dart:io' as io; : line 2
static Future
Here's the working pubspec dep for a fork with the change above:
advance_pdf_viewer:
git:
url: https://github.com/AdiD253/pdf_viewer.git
ref: pdf-viewer-file-fix
Came across this issue after upgrading to Flutter 2.2.1 and even the same persisted after downgrading it to 2.2.0.
Sol, that worked:
Edited the /flutter/.pub-cache/hosted/pub.dartlang.org/advance_pdf_viewer-2.0.0/lib/src/document.dart
import 'dart:io'; - > import 'dart:io' as io; : line 2
static Future fromAsset(String asset) async { io.File file; // Edited try { var dir = await getApplicationDocumentsDirectory(); file = io.File("${dir.path}/file.pdf"); // Edited var data = await rootBundle.load(asset); var bytes = data.buffer.asUint8List(); await file.writeAsBytes(bytes, flush: true); } catch (e) { throw Exception('Error parsing asset file!'); } PDFDocument document = PDFDocument(); document._filePath = file.path; try { var pageCount = await _channel .invokeMethod('getNumberOfPages', {'filePath': file.path}); document.count = document.count = int.parse(pageCount); } catch (e) { throw Exception('Error reading PDF!'); } return document; }
This has to be fixed asap.
Came across this issue after upgrading to Flutter 2.2.1 and even the same persisted after downgrading it to 2.2.0. Sol, that worked: Edited the /flutter/.pub-cache/hosted/pub.dartlang.org/advance_pdf_viewer-2.0.0/lib/src/document.dart import 'dart:io'; - > import 'dart:io' as io; : line 2 static Future fromAsset(String asset) async { io.File file; // Edited try { var dir = await getApplicationDocumentsDirectory(); file = io.File("${dir.path}/file.pdf"); // Edited var data = await rootBundle.load(asset); var bytes = data.buffer.asUint8List(); await file.writeAsBytes(bytes, flush: true); } catch (e) { throw Exception('Error parsing asset file!'); } PDFDocument document = PDFDocument(); document._filePath = file.path; try { var pageCount = await _channel .invokeMethod('getNumberOfPages', {'filePath': file.path}); document.count = document.count = int.parse(pageCount); } catch (e) { throw Exception('Error reading PDF!'); } return document; }
This has to be fixed asap.
Submitted a PR containing the fix- https://github.com/lohanidamodar/pdf_viewer/pull/51.
Came across this issue after upgrading to Flutter 2.2.1 and even the same persisted after downgrading it to 2.2.0.
Sol, that worked:
Edited the /flutter/.pub-cache/hosted/pub.dartlang.org/advance_pdf_viewer-2.0.0/lib/src/document.dart
import 'dart:io'; - > import 'dart:io' as io; : line 2
static Future fromAsset(String asset) async { io.File file; // Edited try { var dir = await getApplicationDocumentsDirectory(); file = io.File("${dir.path}/file.pdf"); // Edited var data = await rootBundle.load(asset); var bytes = data.buffer.asUint8List(); await file.writeAsBytes(bytes, flush: true); } catch (e) { throw Exception('Error parsing asset file!'); } PDFDocument document = PDFDocument(); document._filePath = file.path; try { var pageCount = await _channel .invokeMethod('getNumberOfPages', {'filePath': file.path}); document.count = document.count = int.parse(pageCount); } catch (e) { throw Exception('Error reading PDF!'); } return document; }
This solution doesn't work for me with Flutter 2.2.1
`[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Exception: Error reading PDF!
not working on MacOS desktop app Android and iOS working well
Came across this issue after upgrading to Flutter 2.2.1 and even the same persisted after downgrading it to 2.2.0.
Sol, that worked:
Edited the /flutter/.pub-cache/hosted/pub.dartlang.org/advance_pdf_viewer-2.0.0/lib/src/document.dart
import 'dart:io'; - > import 'dart:io' as io; : line 2
static Future fromAsset(String asset) async { io.File file; // Edited try { var dir = await getApplicationDocumentsDirectory(); file = io.File("${dir.path}/file.pdf"); // Edited var data = await rootBundle.load(asset); var bytes = data.buffer.asUint8List(); await file.writeAsBytes(bytes, flush: true); } catch (e) { throw Exception('Error parsing asset file!'); } PDFDocument document = PDFDocument(); document._filePath = file.path; try { var pageCount = await _channel .invokeMethod('getNumberOfPages', {'filePath': file.path}); document.count = document.count = int.parse(pageCount); } catch (e) { throw Exception('Error reading PDF!'); } return document; }
Requires another change to Line 22:
static Future<PDFDocument> fromFile(File file) aync
to
static Future<PDFDocument> fromFile(io.File file) aync
Sadly still not working with Exception Error parsing asset file!
with example code provided by the package.
Just switched from flutter_plugin_pdf_viewer to advance_pdf_viewer, and facing 3 issues while running the app. These are the 3 issues :
1) ../../Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/advance_pdf_viewer-2.0.0/lib/src/document.dart:64:14: Error: The class 'File' is abstract and can't be instantiated. file = File("${dir.path}/file.pdf");
2) ../../Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/advance_pdf_viewer-2.0.0/lib/src/document.dart:72:26: Error: Non-nullable variable 'file' must be assigned before it can be used. document._filePath = file.path;
3) ../../Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/advance_pdf_viewer-2.0.0/lib/src/document.dart:75:58: Error: Non-nullable variable 'file' must be assigned before it can be used. .invokeMethod('getNumberOfPages', {'filePath': file.path});
I am using this code:
` class _ChapterState extends State {
bool _isLoading = true;
PDFDocument document;
@override void initState() { super.initState(); loadDocument(); }
loadDocument() async { document = await PDFDocument.fromAsset(widget.category.chapter); setState(() => _isLoading = false); }
@override Widget build(BuildContext context) { return Scaffold( backgroundColor: Theme.of(context).scaffoldBackgroundColor, appBar: AppBar( centerTitle: false, backgroundColor: Theme.of(context).accentColor, title: Text( widget.category.name, ), ), body: Center( child: _isLoading ? Center( child: CircularProgressIndicator(), ) : PDFViewer(document: document), ), ); } } ` Kindly help.