PdfViewer class

A widget that displays a PDF with a thumbnail sidebar for navigation.

This widget combines a PDF viewer with a sidebar that shows thumbnails of all pages. Users can navigate through the PDF by swiping or by tapping on thumbnails in the sidebar.

Rendering is backed by pdfrx (PDFium), with page preloading and progressive rendering.

Inheritance

Constructors

PdfViewer({Key? key, String? pdfPath, Uint8List? pdfData, bool initialSidebarOpen = false, double sidebarWidth = 160, double thumbnailHeight = 150, Color sidebarBackgroundColor = Colors.grey, BoxDecoration? selectedPageDecoration, bool showZoomHint = true, int initialPage = 1, bool showPageIndicator = true, void onPageChanged(int page)?, PanAxis panAxis = PanAxis.free, Color backgroundColor = Colors.grey, ValueChanged<double>? onScroll, void onError(Object error)?, Widget errorBuilder(BuildContext context, Object error)?, PdfSemanticLabels semanticLabels = const PdfSemanticLabels(), PdfViewerController? controller})
Creates a PdfViewer widget.
const

Properties

backgroundColor Color
Background color shown behind and between the pages.
final
controller PdfViewerController?
Controller driving the document's scroll and zoom.
final
errorBuilder Widget Function(BuildContext context, Object error)?
Builds the widget shown when the document fails to load or parse.
final
hashCode int
The hash code for this object.
no setterinherited
initialPage int
The page to show when first opening the document (1-indexed). Defaults to 1.
final
initialSidebarOpen bool
Whether the sidebar should be initially open
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onError → void Function(Object error)?
Called when the document fails to load or parse.
final
onPageChanged → void Function(int page)?
Called whenever the current page changes.
final
onScroll ValueChanged<double>?
Called when the viewer's vertical scroll offset changes (in view pixels, 0 = top of the document). Useful to collapse/expand surrounding chrome (header, toolbar) while the user reads.
final
panAxis PanAxis
How panning is constrained while dragging the document.
final
pdfData Uint8List?
Raw bytes of a PDF document, displayed directly without any path or URL.
final
pdfPath String?
Path to a PDF file. Can be a URL (starting with http:// or https://) or an asset path.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selectedPageDecoration BoxDecoration?
Optional decoration for the selected page thumbnail
final
semanticLabels PdfSemanticLabels
Semantic labels used for accessibility (screen readers).
final
showPageIndicator bool
Whether to show a page indicator overlay (e.g. "3 / 12") on the viewer.
final
showZoomHint bool
Whether to show the zoom hint animation on first load
final
sidebarBackgroundColor Color
Background color of the sidebar
final
sidebarWidth double
Width of the sidebar containing thumbnails
final
thumbnailHeight double
Height of each thumbnail in the sidebar
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<PdfViewer>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

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