In Flutter there are two ways of adding touch listeners.
If the Widget supports event detection, pass a function to it and handle it in the function. For example, the RaisedButton has an onPressed parameter:.
Using the GestureDetector, you can listen to a wide range of Gestures such as:.
Tap.
OnTapDown - A pointer that might cause a tap has contacted the screen at a particular location.
OnTapUp - A pointer that triggers a tap has stopped contacting the screen at a particular location.
OnTap - A tap has occurred.
OnTapCancel - The pointer that previously triggered the onTapDown won’t cause a tap.
Double tap.
OnDoubleTap - The user tapped the screen at the same location twice in quick succession.
Long press.
OnLongPress - A pointer has remained in contact with the screen at the same location for a long period of time.
Vertical drag.
OnVerticalDragStart - A pointer has contacted the screen and might begin to move vertically.
OnVerticalDragUpdate - A pointer in contact with the screen has moved further in the vertical direction.
OnVerticalDragEnd - A pointer that was previously in contact with the screen and moving vertically is no longer in contact with the screen and was moving at a specific velocity when it stopped contacting the screen.
Horizontal drag.
OnHorizontalDragStart - A pointer has contacted the screen and might begin to move horizontally.
OnHorizontalDragUpdate - A pointer in contact with the screen has moved further in the horizontal direction.
OnHorizontalDragEnd - A pointer that was previously in contact with the screen and moving horizontally is no longer in contact with the screen and was moving at a specific velocity when it stopped contacting the screen.
The following example shows a GestureDetector that rotates the Flutter logo on a double tap:.