viewerOverlayBuilder property
Add overlays to the viewer.
This function is to generate widgets on PDF viewer's overlay Stack. The widgets can be laid out using layout widgets such as Positioned and Align.
The most typical use case is to add scroll thumbs to the viewer. The following fragment illustrates how to add vertical and horizontal scroll thumbs:
viewerOverlayBuilder: (context, size, handleLinkTap) => [
PdfViewerScrollThumb(
controller: controller,
orientation: ScrollbarOrientation.right),
PdfViewerScrollThumb(
controller: controller,
orientation: ScrollbarOrientation.bottom),
],
For more information, see PdfViewerScrollThumb.
To handle tap-like overlay interactions while still allowing the viewer to
handle panning, zooming, and link taps, wrap the overlay with
PdfOverlayInteractionRegion.
Note for using GestureDetector inside viewerOverlayBuilder:
Prefer PdfOverlayInteractionRegion when the overlay only needs tap,
double tap, long press, or secondary tap.
You may want to use GestureDetector inside viewerOverlayBuilder to handle lower-level gesture events. In such cases, your GestureDetector eats the gestures and the viewer cannot handle them directly. So, when you use GestureDetector inside viewerOverlayBuilder, please ensure the following things:
- GestureDetector.behavior should be HitTestBehavior.translucent
- GestureDetector.onTapUp (or such depending on your situation) should call
handleLinkTapto handle link tap
The following fragment illustrates how to handle link tap in GestureDetector:
viewerOverlayBuilder: (context, size, handleLinkTap) => [
GestureDetector(
behavior: HitTestBehavior.translucent,
onTapUp: (details) => handleLinkTap(details.localPosition),
// Make the GestureDetector covers all the viewer widget's area
// but also make the event go through to the viewer.
child: IgnorePointer(child: SizedBox(width: size.width, height: size.height)),
...
),
...
]
Implementation
final PdfViewerOverlaysBuilder? viewerOverlayBuilder;