How do I detect more than one gesture on a single widget in flutter? - flutter

I want to listen for tap events on a widget and take one action for that, and a hold event and take a different action for that. It looks like flutter gesture detector can only detect a single gesture? This seems like it would be hugely limiting for mobile development though, so I figured there must be a way to detect two different gestures on one widget. How would I do that?

if you see the api docs, you will see there are detectors like doubletap, longpress etc
https://api.flutter.dev/flutter/widgets/GestureDetector-class.html

Related

Flutter - how to have a widget respond to touch and flick?

Currently in the design phase of an app. One of the goals we have is to be able to touch a certain widget, and on tap and hold, have the widget then follow the user's finger where they drag.
Then, if the user releases gently, the widget snaps back to the original location.
However, if the user flicks the widget, we want the widget to fly across the screen, reacting correctly to the user's flick.
Is there anything built-in that can handle this? Also, if this needs to be explained more to make sense, happy to elaborate.
Thanks!
I think for such cases you can use GestureDetector widget. It provides several useful functions. See here:
https://api.flutter.dev/flutter/widgets/GestureDetector-class.html
You can use onPanStart of GestureDetector and then get the offset and use it to move the widget accross the screen.

Animate card widget on button click Tinder like swipe

Hello all I am building Tinder like swipe in Flutter. So far so good I have made the stack of cards together with the gesture detector when the user swipes left/right. However my issue come when I try to animate on click of a button. Under the stack of cards there are 2 buttons which you can like or dislike on button click. I would like to get an advice how I can approach the animation when the user clicks on either button. Below is my code for displaying the stack. Best wishes
There are several options to animate the card off screen. Since you're already using a Stack, AnimatedPosition is probably the best option.
You could also use Transform.translate to set the transform property of an AnimatedContainer. Or, if you want more control over the animation you could use a SlideTransition.
For a good overview of how to decide which animations you need, see this video from two days ago: https://www.youtube.com/watch?v=GXIJJkq_H8g
There's also https://pub.dev/packages/animations for more pre-packed options.

How to animate fullscreen photo transition on swipe, like in Telegram?

When you swipe vertically, image is dragged towards the swipe, with fading out animation of black background.
And after release, it smoothly returns to it's previous position on the screen, like Hero animation does.
How is it possible to recreate such an effect using Flutter? The same scenario, in fullscreen photo view.
photo_view package is desired for fullscreen, so it shouldn't interfere with zooming.
What you need is actually an out-of-the-box widget, and it's surprisingly easy to use. It's called Hero. Basically, you wrap the widget you want to animate like that in a Hero widget, with a specific tag string, and, when you navigate to another screen, you wrap the destination widget in another Hero with the same tag. An effect like the one you shared can be achieved by wrapping two widgets with the same photo with Heroes in different PageRoutes.
Check out this Flutter widget of the week video to get you started, and this Flutter.dev article for a more detailed explanation on Hero widgets.
Edit: I see you are looking for a more specific image-viewer behavior. Then, I suggest you use the photo_view package, which includes many functionalities to visualize images, including the hero transition with swipe-dow-to-dismiss behaviors, pinching to zoom, etc.
I found the solution.
To create such an animation, you should use extended_image package, which has SlideOutPage widget for creation of such transitions.

Flutter pan/zoom via gesture or function

My goal is to have a container of some sort, that I can zoom and pan via gestures, but also need to be able to zoom and pan to a specific location in the container via a button. I've tried all sorts of combinations of GestureDetector's mixed with Matrix4Transform and MatrixGestureDetector but am not having any luck allowing both hand and function initiated gestures to work together. Does anyone have something like this already working, and if so could you share any hints? Thanks
Take a look at this package: photo_view.

Manage gestures priority between two widgets

I'm experimenting using the google maps for flutter plugin but I'm running into a problem managing the gesture priority.
My map, which need to handle gestures is rendered inside a PageView which also listen to some gestures. The thing is, It appears that the gesture handler of PageView take the priority over the map one, so if I drag vertically on the map, the map move but if I drag horizontally on the map, the page will switch instead of the map moving.
Is there a way to manage the priority between gesture handlers of widget to fix this sort of problems?