PdfViewer class
A complete PDF viewer widget with page navigation and zoom support.
Displays PDF pages from a PdfViewerController in a scrollable, zoomable view with optional page navigation controls.
Usage Modes
Mode 1: Preview a programmatically created PDF
final doc = PdfDocument();
doc.pages.add().graphics.drawString('Hello', font, bounds: bounds);
PdfViewer(
controller: PdfViewerController.fromDocument(doc),
)
Mode 2: Preview a PDF from base64
PdfViewer(
controller: PdfViewerController.fromBase64(base64String),
)
Mode 3: Preview a PDF from bytes
PdfViewer(
controller: PdfViewerController.fromBytes(pdfBytes),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- PdfViewer
Constructors
- PdfViewer({Key? key, required PdfViewerController controller, bool showPageIndicator = true, bool enableZoom = true, double minScale = 0.5, double maxScale = 4.0, Color backgroundColor = const Color(0xFFEEEEEE), double pageSpacing = 16.0, bool continuousScroll = true, Widget pageBuilder(BuildContext context, int pageIndex, Widget pageWidget)?, void onPageChanged(int pageIndex)?})
-
const
Properties
- backgroundColor → Color
-
Background color behind the pages.
final
- continuousScroll → bool
-
Whether to scroll continuously through all pages or show one at a time.
final
- controller → PdfViewerController
-
Controller that manages the PDF document and page state.
final
- enableZoom → bool
-
Whether to enable pinch-to-zoom.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- maxScale → double
-
Maximum zoom scale.
final
- minScale → double
-
Minimum zoom scale.
final
- onPageChanged → void Function(int pageIndex)?
-
Callback when a page becomes visible.
final
- pageBuilder → Widget Function(BuildContext context, int pageIndex, Widget pageWidget)?
-
Optional builder for custom page decoration.
final
- pageSpacing → double
-
Spacing between pages in continuous scroll mode.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
Whether to show built-in page navigation controls.
final
- showPageIndicator → bool
-
Whether to show the page indicator (e.g., "Page 1 of 5").
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