Flutter – Gestures
Gestures are used to interact with an application. It is generally used in touch-based devices to physically interact with the application. It can be as simple as a single tap on the screen to a more complex physical interaction like swiping in a specific direction to scrolling down an application. It is heavily used in gaming and more or less every application requires it to function as devices turn more touch-based than ever. In this article, we will discuss them in detail.
Some widely used gestures are mentioned here :
- Tap: Touching the surface of the device with the fingertip for a small duration of time period and finally releasing the fingertip.
- Double Tap: Tapping twice in a short time.
- Drag: Touching the surface of the device with the fingertip and then moving the fingertip in a steadily and finally releasing the fingertip.
- Flick: Similar to dragging, but doing it in a speedier way.
- Pinch: Pinching the surface of the device using two fingers.
- Zoom: Opposite of pinching.
- Panning: Touching the device surface with the fingertip and moving it in the desired direction without releasing the fingertip.
The GestureDetector widget in flutter is used to detect physical interaction with the application on the UI. If a widget is supposed to experience a gesture, it is kept inside the GestureDetector widget. The same widget catches the gesture and returns the appropriate action or response.
Below is the list of gestures and their corresponding events :
Flutter supports Listener widgets that are low-level gesture detection mechanism. It detects user interaction and dispatches one of the below mentioned corresponding events:
Flutter also has widgets to do specific as well as advanced gestures. These widgets are as below :
- Dismissible: Supports flick gesture to terminate the widget.
- Draggable: Supports drag gesture to make the widget mobile.
- LongPressDraggable: If the parent widgets are draggable, it supports the drag gesture to move the children widget.
- DragTarget: Accepts any Draggable widget
- IgnorePointer: When used it hides the widget and its corresponding children from the gesture detection process.
- AbsorbPointer: Stops the gesture detection process itself to avoid action dispatch on overlapping widgets.
- Scrollable: Makes content available inside the widget scrollable.