Flutter — GestureDetector Widget #2

Karthik Ponnam
2 min readJan 12, 2019

--

Hello All,

Most the widgets in flutter provide onPress and onTap gestures by default. Some times we need more gestures to make our desired action to run so in order to achive this Flutter team provide a widget called GestureDetecor

So Let’s get started

What is GestureDetector

GestureDetector is a widget where we can make any widget to react to our Gestures

Notes

If this widget has a child, it defers to that child for its sizing behavior. If it does not have a child, it grows to fit the parent instead.

* If GestureDetector child is invisible then it will ignore touches by default.

* If GestureDetector does not have a child, it grows to fit the parent instead.

* To see how large the hit test box of a [GestureDetector] is for debugging purposes, set [debugPaintPointersEnabled] to true.

* Pan and scale callbacks cannot be used simultaneously because scale is a superset of pan.

* Horizontal and vertical drag callbacks cannot be used simultaneously because a combination of a horizontal and vertical drag is a pan.

as

Basic GestureDetector use

Options available with GestureDetector are:

behavior → HitTestBehavior

This defaults to HitTestBehavior.deferToChild if child is not null and HitTestBehavior.translucent if child is null

child → Widget

Widget

onDoubleTap → GestureTapCallback

onHorizontalDragCancel → GestureDragCancelCallback

onHorizontalDragDown → GestureDragDownCallback

for more details about DragDownDetails visit here

onHorizontalDragEnd → GestureDragEndCallback

for more details about DragEndDetails visit here

onHorizontalDragStart → GestureDragStartCallback

for more details about DragEndDetails visit here

onHorizontalDragUpdate → GestureDragUpdateCallback

for more details about DragEndDetails visit here

onLongPress → GestureLongPressCallback

onLongPressUp → GestureLongPressUpCallback

onPanCancel → GestureDragCancelCallback

onPanDown → GestureDragDownCallback

onPanEnd → GestureDragEndCallback

onPanStart → GestureDragStartCallback

onPanUpdate → GestureDragUpdateCallback

onScaleEnd → GestureScaleEndCallback

onScaleStart → GestureScaleStartCallback

onScaleUpdate → GestureScaleUpdateCallback

onTap → GestureTapCallback

onTapCancel → GestureTapCancelCallback

onTapDown → GestureTapDownCallback

onTapUp → GestureTapUpCallback

onVerticalDragCancel → GestureDragCancelCallback

onVerticalDragDown → GestureDragDownCallback

onVerticalDragEnd → GestureDragEndCallback

onVerticalDragStart → GestureDragStartCallback

onVerticalDragUpdate → GestureDragUpdateCallback

Using GestureDetector We can more detect swipe left, right, top and bottom and can perform action accordingly.

If you want to develop your own gesture recognizers you need to use RawGestureDetector more here

Thanks for your time.

Hope you like it, if yes clap & share.

--

--

Karthik Ponnam
Karthik Ponnam

Written by Karthik Ponnam

❤️ to Code. Full Stack Developer, Flutter, Android Developer, Web Development, Known Languages Java, Python so on.,

No responses yet