Flutter – Gestures

Hi Friends,

Hope you are all well. In this post let’s talk something about gestures and see how to bring them into our flutter apps.

Let’s begin.

To learn the basics of flutter get my course – Click here.

Other flutter courses – here. (Affliate link)

A screencast of this post

Gestures are an interesting way to allow the user to interact with your app. For instance., when your screen is locked, you slide your finger across the screen to unlock it right ? That’s a simple gesture. Tapping on a button, Tapping and holding an app icon to drag it across screens; all these are various gestures that you use everyday to interact with your phone.

So, how do we bring these gestures in our applications. Let’s see that with a simple onTap() example in this post. Assume that you want a button with specific dimensions and a specific design. Now flutter by default comes with RaisedButton, Flat, Floating action and other button designs. To create a custom button the best way is to create a widget, design it to your desired specification and add the onTap() functionality to it.

Create a new Flutter project. Open the main.dart file and modify it as shown below.

This is a simple gesture detector that detects a tap gesture on a particular container. Now., when you run this you’ll notice a button with rounded edges on the center of the screen. Tap on it and you will notice that your container now behaves like a button. Similarly you could try it out with doubleTap() and other gestures as well.

If you noticed, you would see that the ripple effect is not replicated whenever the button is tapped. To show the ripple effect, simply use an InkWell.

Now you’ll notice the ripple effect.

Wait, what if there is more than one gesture arriving at a time. This scenario is called a gesture disambiguation and this is resolved by making the gestures fight one another in the arena. Yeah, That’s right. We’ll talk more about this in our forth-coming posts.

Hope this helped you guys. If you found this helpful, kindly share it with someone and help them too.

Donate – Click here.

Join our discord community – Click here.

Thanks for reading. Peace.. :)

 

 

Liked it? Take a second to support admin on Patreon!