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.
The GestureDetector comes with a wide variety of properties. We could, for example, add a secret that is shown only on double tap.
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
Detecting gestures
0 / 60 points
The assignment template comes with an application used for adding items similar to applications that we’ve worked on earlier. In this assignment, your task is to add gesture detection functionality to the application.
There are two gestures to react to. First, if a card is tapped, the value shown in the tapped card should be incremented by one. Second, if a card is swiped to the left, it should be removed.
For detecting the swipe, instead of GestureDetector, study and use a widget called Dismissible. Note that swipe to the right should not be allowed. The Dismissible widget has a property direction that can be used to control the allowed directions.