I'm using flutter_pdfview to display a PDF in my
Flutter App. Under the hood, the PDFView widget uses an AndroidView or a UiKitView depending on the platform.
I would like to get the coordinates of a tap event relatively to the PDF document knowing that a user can zoom and pan on the PDF.
For this, I would need to subscribe to scale and pan events in order to know which part of the document is currently displayed on the screen. Then I could figure out where exactly the user taps.
I've tried passing my own ScaleGestureRecognizer
and PanGestureRecognizer
. Unfortunately, the onUpdate()
, onStart()
never seem to be triggered.
Here's my code:
class PDFViewer extends StatelessWidget {
PDFViewer({this.filePath});
final String filePath;
@override
Widget build(BuildContext context) {
final scale = ScaleGestureRecognizer()
..onUpdate = (details) {
print(details.scale);
};
final pan = PanGestureRecognizer()
..onUpdate = (details) {
print(details.delta);
}
..onStart = (_) {
print('Start pan');
}
..onEnd = (_) {
print('End pan');
};
return PDFView(
filePath: filePath,
gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{
Factory<ScaleGestureRecognizer>(() => scale),
Factory<PanGestureRecognizer>(() => pan),
},
);
}
}