PdfViewer constructor
- 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.
Provide exactly one PDF source:
pdfPath: a URL (starting with http:// or https://) or an asset path.pdfData: the raw bytes of the PDF document.
The initialSidebarOpen parameter determines whether the thumbnail sidebar
is initially visible.
The sidebarWidth parameter sets the width of the thumbnail sidebar.
The thumbnailHeight parameter sets the height of each thumbnail in the sidebar.
The sidebarBackgroundColor parameter sets the background color of the sidebar.
The selectedPageDecoration parameter sets the decoration for the selected page thumbnail.
The showZoomHint parameter determines whether to show an animated hint
indicating that the user can pinch to zoom. Defaults to true.
The initialPage parameter sets the page shown on first open. Defaults to 1.
The showPageIndicator parameter shows a "current / total" overlay. Defaults to true.
The onPageChanged callback is called whenever the user navigates to a new page.
The panAxis parameter constrains panning (e.g. PanAxis.aligned locks
each gesture to its dominant axis). Defaults to PanAxis.free.
The backgroundColor parameter sets the color behind and between the
pages. Defaults to Colors.grey.
The onScroll callback reports the vertical scroll offset (in view
pixels, 0 = top), e.g. to collapse surrounding chrome while reading.
The onError callback is invoked when the document fails to load or
parse (network/asset error or corrupt/encrypted PDF).
The errorBuilder parameter customises the widget shown on failure.
Defaults to a centred icon with a visible, screen-reader-announced message.
The semanticLabels parameter allows customising the labels announced by
screen readers (VoiceOver / TalkBack). Defaults to English labels.
The controller parameter lets the caller drive the scroll/zoom position
(e.g. go to a page, or forward a drag from a surrounding header). When
null, the viewer creates its own.
Implementation
const PdfViewer({
super.key,
this.pdfPath,
this.pdfData,
this.initialSidebarOpen = false,
this.sidebarWidth = 160,
this.thumbnailHeight = 150,
this.sidebarBackgroundColor = Colors.grey,
this.selectedPageDecoration,
this.showZoomHint = true,
this.initialPage = 1,
this.showPageIndicator = true,
this.onPageChanged,
this.panAxis = PanAxis.free,
this.backgroundColor = Colors.grey,
this.onScroll,
this.onError,
this.errorBuilder,
this.semanticLabels = const PdfSemanticLabels(),
this.controller,
}) : assert(
pdfPath != null || pdfData != null,
'Either pdfPath or pdfData must be provided.',
),
assert(
pdfPath == null || pdfData == null,
'Provide only one of pdfPath or pdfData, not both.',
);