5 User Interaction: Forms and Gestures

 

This chapter covers:

In this chapter:

  • User interaction with GestureDetectors
  • Special interaction widgets such as Dismissible
  • Creating forms in Flutter
  • Text input, dropdown lists, and more form elements
  • Using Keys to manage Flutter forms

This chapter is about letting users interact with your Flutter app. At the end of the day, all applications have one important job: to make it easy for a human to interact with data. And one side of that interaction is allowing users not only to look at data, but also add to it and change it. This chapter is about that: letting users add and change data in your app. Specifically, this covers two different kinds of interaction: gestures and forms.

5.1  User interaction and gestures

Gestures are any kind of interaction event: taps, drags, pans, and more. First I’ll cover how you detect and respond to these user gestures. To be honest, though, there isn’t much involved here. Flutter has a convenience widget that allows you to add gesture detectors to any location of the widget tree that you’d like.

Without knowing it, perhaps, you’ve already used gestures. All the button widgets that have onPressed and onTap are just convenient wrappers around gesture detectors. GestureDetectors are used in a similar way.

5.1.1  The GestureDetector widget

5.1.2  The GestureDetector in practice

5.1.3  Dismissible

5.2  Flutter Forms

5.2.1  The Form widget

5.2.2  GlobalKey<FormState>

5.3  FormField widgets

5.3.1  TextFormField

5.3.2  DropdownFormButton

5.3.3  Generic Form Fields

5.4  Form UI and working with focus nodes

5.4.1  InputDecoration

5.4.2   Improve UI with FocusNodes

5.5  Form methods help manage form state

5.5.1  Form.onChange

5.5.2  FormState.save

5.5.3  Form.onWillPop

5.6  Summary

sitemap