skip to Main Content

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)),
                ],
              ),
            ),

2

Answers


  1. Chosen as BEST ANSWER

    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.

    What I came up with:

    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,
                  ),
                )
    
         ],
     ),
    

  2. We have prepared a workaround to retrieve the tapped coordinates when the user taps the SfPdfViewer, which can be downloaded from the following link,
    https://www.syncfusion.com/downloads/support/directtrac/general/ze/tapped_position-721291336
    Please find the workflow for this example application below,

    We have used the TapGestureRecoginzer to catch the tap action and onTapDown callback we have called _getPdfCoordinates() method, it has the logic to return the tapped location coordinates relative to the PDF page.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search