Viewer events and notifications
Nutrient Flutter SDK allows you to listen to various events that occur when the end user interacts with Nutrient.
PspdfkitWidget events
Nutrient Flutter SDK supports the following events:
-
onDocumentLoaded
— Called when a document is loaded with the loadedPdfDocument
object. This event is triggered after the document is loaded and the first page is rendered. -
onDocumentLoadFailed
— Called when a document fails to load. The event delivers an error message with the reason for the failure. -
onPageChanged
— Called when a page is changed with the new page index. This event is triggered when a document is first loaded or when a user navigates to a new page. -
onPageClicked
— Called when a page is clicked with the page index. This event is triggered when a user clicks on a page.
To listen to these events, add an event listener to the PspdfkitWidget
:
PspdfkitWidget( document: document_path, onDocumentLoaded: (pdfDocument) { print('Document loaded'); }, onDocumentLoadFailed: (error) { print('Document load failed: $error'); }, onPageChanged: (pageIndex) { print('Page changed to $pageIndex'); }, onPageClicked: (pageIndex) { print('Page clicked: $pageIndex'); }, );
Present mode events
The following table lists the events supported by Nutrient Flutter SDK in present mode.
Event | Description |
---|---|
flutterPdfActivityOnPause |
Android only. Called when the PDF activity is paused. |
pdfViewControllerWillDismiss |
iOS only. Called right before the dismissal of the PDF view controller. |
pdfViewControllerDidDismiss |
iOS only. Called right after the dismissal of the PDF view controller. |
Implementing a callback method
The example below shows how to implement a callback to get notified when the PDF activity is paused or when the PDF view controller is about to be dismissed.
// First, implement the callback methods: void flutterPdfActivityOnPauseHandler() { print('flutterPdfActivityOnPauseHandler'); } void pdfViewControllerWillDismissHandler() { print('pdfViewControllerWillDismissHandler'); } void pdfViewControllerDidDismissHandler() { print('pdfViewControllerDidDismissHandler'); } // Next, register these callbacks with `Pspdfkit` once. This can be done in the `build` method of your widget. Pspdfkit.flutterPdfActivityOnPause = () => flutterPdfActivityOnPauseHandler(); Pspdfkit.pdfViewControllerWillDismiss = () => pdfViewControllerWillDismissHandler(); Pspdfkit.pdfViewControllerDidDismiss = () => pdfViewControllerDidDismissHandler();
Now, whenever any of these events happen, the corresponding method will trigger and print the relevant text.