Search code examples
flutterdartflutter-dependenciesflutter-video-player

How to add a double tap gesture to video player without loosing the focus of controls?


I tried it by wrapping the

return ClipRRect(
            borderRadius: BorderRadius.circular(30.0),
            child: Chewie(
              controller: _chewieController,
            )

with

return Stack(
            children: [
              ClipRRect(
                borderRadius: BorderRadius.circular(30.0),
                child: Chewie(
                  controller: _chewieController,
                ),
              ),
              Positioned.fill(child: GestureDetector(
                onDoubleTap: (){
                  print('its double tapped ');
                },
                child: Container(
                  color: Colors.transparent,
                  height: double.infinity,
                  width: double.infinity,
                ),))
            ],
          );

Now I am able to doubleTap, but with a single tap, controllers don't appear, Is there any way I can achieve both things.
With a doubleTap, I can call the like function and with onTap to show the controllers.
the package used above chewie 0.12.0


Solution

  • return GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTapDown: (_) {
                  setState(() {
                    isMute = !isMute;
                    _chewieController.setVolume(isMute ? 0 : 1);
                  });
                },
                onDoubleTap: (){
                  print('liked');
                },
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(30.0),
                  child: Chewie(
                    controller: _chewieController,
                  ),
                ),
              );
    

    on simple onTap on video, it shows the controller, onTap here is not getting override hence
    onTapDown is used as an alternative to onTap to mute the video.