Interacting with External Systems and Devices

Handling Gestures


Learning Objectives

  • You know the very basics of handling gestures.

Plenty of devices have touch screens, and there are plenty of applications where the main mode of interaction is gestures made on the screen. A good starting point for building interfaces that react to gestures is the GestureDetector widget, which provides a wide variety of actions that can be reacted to. GestureDetector can be given a child widget and a set of actions as properties to react to.

The following example shows the use of GestureDetector. In the following example, we create a yellow container, which contains the text “Hello”. When the container is tapped, the text changes.

Run the program to see the output

The GestureDetector comes with a wide variety of properties. We could, for example, add a secret that is shown only on double tap.

Run the program to see the output

Although we only briefly touched the GestureDetector, there are also other widgets for handling gestures. As an example, the InkWell widget can be used to provide an additional effect when a widget is tapped. For additional information on how the gestures are detected, check out Flutter’s documentation on the topic

Loading Exercise...