JumpToPage Web throws an Exception
Calling jumpToPage with Flutter web it does not work
final pdfController = PdfController(
document: PdfDocument.openAsset('assets/mypdf.pdf'),
);
return PdfView(
controller: pdfController,
scrollDirection: Axis.vertical,
onDocumentLoaded: (_) => pdfController.jumpToPage(3),
);
Exception:
InternalError: frontend server failed to compile '_positions' Error: Expected a value of type 'Exception', but got one of type 'AssertionErrorImpl' at Object.throw_ [as throw] (http://localhost:59065/dart_sdk.js:4336:11) at Object.castError (http://localhost:59065/dart_sdk.js:4307:15) at Object.cast [as as] (http://localhost:59065/dart_sdk.js:4623:17) at dart.LegacyType.new.as (http://localhost:59065/dart_sdk.js:6192:60) at http://localhost:59065/packages/native_pdf_view/src/native_pdf_view.dart.lib.js:1261:46 at native_pdf_view.PdfController.new._loadDocument (http://localhost:59065/packages/native_pdf_view/src/native_pdf_view.dart.lib.js:1264:13) at _loadDocument.next (<anonymous>) at http://localhost:59065/dart_sdk.js:37672:33 at _RootZone.runUnary (http://localhost:59065/dart_sdk.js:37526:58) at _FutureListener.thenAwait.handleValue (http://localhost:59065/dart_sdk.js:32500:29) at handleValueCallback (http://localhost:59065/dart_sdk.js:33047:49) at Function._propagateToListeners (http://localhost:59065/dart_sdk.js:33085:17) at _Future.new.[_completeWithValue] (http://localhost:59065/dart_sdk.js:32928:23) at async._AsyncCallbackEntry.new.callback (http://localhost:59065/dart_sdk.js:32950:35) at Object._microtaskLoop (http://localhost:59065/dart_sdk.js:37787:13) at _startMicrotaskLoop (http://localhost:59065/dart_sdk.js:37793:13) at http://localhost:59065/dart_sdk.js:33302:9
Hi, as state on pub.dev, this plugin is only compatible with Android and iOS
I fixed it adding a delay of few milliseconds before jumpToPage:
Timer(Duration(milliseconds: 10), () { pdfController.jumpToPage(page); });
ok, now i see the problem, your controller has to be set in the onViewCreated function callback:
onViewCreated: (PDFViewController pdfViewController) {
pdfController = pdfViewController;
}