ViewerController class

State controller for a PDF viewer widget.

ViewerController is a ChangeNotifier that holds all view-level state for a single open PDF document: the current page, zoom mode, annotation rendering toggle, and active search matches. Listeners (typically PageView and the example app's toolbar) rebuild whenever any of these values change.

Ownership

One ViewerController should be created per open document and disposed when the document is closed. The controller does not own the PdfDocument handle; that remains owned by the caller (e.g. DocumentState in the example app).

Example

final controller = ViewerController();
// Navigate to the third page (zero-based index 2):
controller.setPage(2, pageCount: doc.pageCount);
// Switch to fit-page zoom:
controller.setZoom(ZoomMode.fitPage);
// Toggle annotation rendering:
controller.renderAnnotations = !controller.renderAnnotations;
// Remember to dispose when the document is closed:
controller.dispose();
Inheritance

Constructors

ViewerController()
Creates a ViewerController with default settings.

Properties

activeSearchMatches List<PdfSearchMatch>
The current set of search matches to display as overlay highlights.
no setter
currentPage int
The zero-based index of the currently displayed page.
no setter
effectiveZoomFactor double
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
renderAnnotations bool
Whether annotations (highlights, sticky notes, etc.) are rendered in the PDF page. Maps to the PDFium FPDF_ANNOT flag.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
searchCompleted bool
Whether the last search run for this document completed.
getter/setter pair
searchPageTexts Map<int, String>
Page text cache populated by SearchView as results arrive.
final
searchQuery String
The last query string entered in SearchView for this document.
getter/setter pair
zoomFactor double
The zoom scale factor used when zoomMode is ZoomMode.custom.
no setter
zoomMode ZoomMode
The current zoom mode.
no setter

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
clearSearch() → void
Clears all active search matches and resets persisted search UI state.
dispose() → void
Discards any resources used by the object.
inherited
nextPage({required int pageCount}) → void
Advances to the next page if not already on the last page.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
previousPage() → void
Moves to the previous page if not already on the first page.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
setPage(int pageIndex, {required int pageCount}) → void
Navigates to page pageIndex, clamped to [0, pageCount - 1].
setSearchMatches(List<PdfSearchMatch> matches) → void
Replaces the active search matches and notifies listeners.
setZoom(ZoomMode mode, {double factor = 1.0}) → void
Sets the zoom mode and optional custom scale factor.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited