I'm using syncfusion_flutter_pdfviewer which has its own 'gesture event handler', and I wanted to detect when a user tap on screen to show/hide some buttons.
The problem is that any touch inside the pdf page isn't detected by GestureDetector
So is there a way to force detect touches inside pdf widget or something??
GestureDetector(
onTap: (){
print('click event');
},
child: Stack(
children: [
PdfViewer(filePath: path, pdfKey: _pdfViewerKey, controller: controller,),
TopBar(title: basename(path)),
],
),
),
I referred to this answer from Syncfusion team which implies the use of RawGestureDetector
, but I noticed a delay when detecting taps; also when I performed (pinch to zoom) gesture, an error occurs 90% of the time.
Then I referred to this answer in which they used a GestureDetector
with onPanDown
attribute, but the problem is that it detects any touch before the user left up his finger, and that includs swipes.
1- I put an empty Container
with the size of the screen with a GestureDetector
on top of my PdfView.
2- Normally using a GestureDetector
wouldn't work on an empty Container
so I had to use the HitTestBehavior.translucent
attribute.
3- You can't use a translucid color because that would prevent any touch event on the PdfView.
Stack(
children: [
PdfViewer(),
GestureDetector(
behavior: HitTestBehavior.translucent, //to listen for tap events on an empty container
onTap: () => print("Handle Tap event!!"),
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
),
)
],
),