The Complete Flutter Course: Build Android, iOS and Web Apps
Flutter forms and input validation
For anyone learning to handle typed input, The Complete Flutter Course: Build Android, iOS and Web Apps follows forms from styled fields to checks before saving. This guide traces the portfolio contact form, its working version with Cloud Firestore, and the budget app's expense and income pop-ups, covering mistakes such as unwanted characters, letters in an amount and empty required fields.
Taught by Sagnik Bhattacharya and Paulina Knop
What you will be able to do
You will be able to:
- Give a TextFormField borders and hint text, then create a reusable field widget with named and required parameters.
- Try a regular expression in DartPad before applying it to a form field's validator.
- Filter unwanted keyboard input with an input formatter and limit the length of a field.
- Use TextEditingController to read field values and validators to reject empty required fields.
- Validate the fields together through a Form and GlobalKey, then store the entry in Cloud Firestore and show confirmation.
- Create a pop-up form with validation and an amount field restricted to digits.
Projects
What you will build.
The course has nine projects. These two matter most here.
-
Project 04
Portfolio website and app
Follow a contact form for web and phones that validates input, stores messages in Cloud Firestore, clears its fields and displays a confirmation dialog.
-
Project 08
Budget app
Work with expense and income pop-ups that require only a name and an amount containing digits only before saving.
Lessons
The lessons that matter, in course order.
The Complete Flutter Course: Build Android, iOS and Web Apps has 223 lessons. This page picks out 16 of them, 1 h 46 min of video. Each lesson keeps its number in the course.
Where to start
Lesson 63 Starting the contact form
Begin with Lesson 63, which introduces the portfolio contact form on the landing page built from Lesson 47. Saving to Cloud Firestore begins at Lesson 136, after the Firebase connection at Lesson 123.
16 of 223 lessons · 1 h 46 min
09 Layouts, Gesture and animations: Landing Page Web (Portfolio) Build up the contact form from a TextFormField with borders and hints to a reusable TextForm widget. Explore regular expressions in DartPad, input formatters, validation with error borders and a submit button.
- 63 Start here Starting the contact form A Contact me heading and a TextFormField with a teal outline 6 min
- 64 Borders and hint text for a TextFormField Rounded focused border, Poppins hint text and a field heading 6 min
- 65 Turning the form field into a TextForm widget Named and required parameters and maxLines for taller fields 8 min
- 66 Laying out the contact form Name, email, phone and message fields from TextForm 7 min
- 67 Regular expression basics in Dart RegExp, hasMatch and character ranges tested in DartPad 9 min
- 68 Input formatters with RegExp FilteringTextInputFormatter and a 10-character length limit 5 min
- 69 Validating a form field with RegExp Error borders, autovalidateMode and renaming via Refactor 7 min
- 70 Doubles instead of integers and a submit button Fix int values and style a teal MaterialButton for the form 6 min
17 Add data to Firestore using Flutter: Contact page: Flutter Portfolio Make the contact forms functional with separate field controllers and required first name, email and message validators. Check the Form through its GlobalKey, store messages in Cloud Firestore and display a confirmation dialog.
- 134 Read form fields with TextEditingController One controller per contact field, checked with logger.d 6 min
- 135 Required fields with validators Error messages, a Form widget and a GlobalKey to check them 7 min
- 136 Save contact messages to Firestore An addResponse function that adds to a messages collection 9 min
- 137 A submit dialog for every contact form Reset the form and show an AlertDialog from a shared function 7 min
19 How to reuse code in your Flutter app? (Portfolio app) Extract the phone contact form into a shared widget, then resolve the duplicate key error by assigning a separate GlobalKey to each form.
- 151 Reuse the mobile contact form ContactFormMobile, shared controllers and a GlobalKey per form 4 min
22 Budget App using Flutter Riverpod and MVVM architecture Put together the budget app's add expense pop-up with controllers and a keyed Form. Use a reusable field widget with validation and digits-only input, and check the fields when Save is pressed.
- 195 The add expense pop-up A dialog with a Form, a GlobalKey and two text controllers 6 min
- 196 A reusable text form widget Label, validator, digits-only input and red error borders 7 min
- 197 Name and amount fields for expenses The text form widget in the pop-up, validated on Save 7 min
Instructors
Who teaches it.
Instructor, Flutter
Paulina Knop
Flutter developer and curriculum designer. Teaches the Flutter course.
Questions
Asked before starting.
Where can I learn to make a Flutter form validate typed input?
The Complete Flutter Course: Build Android, iOS and Web Apps from Coding Liquids covers the portfolio contact form with regular expressions and input formatters, its functional version with field reading, required inputs and Cloud Firestore saving, and the budget app's pop-ups with valid amounts. This guide brings together 16 lessons, taking 1 hour 46 minutes, for people working with typed input in an app. It does not cover dropdowns, date pickers or file uploads.
How can my form validate an email address or phone number using a regular expression?
Define the pattern an acceptable entry must match, then use hasMatch in the field's validator to test it and return an error message if it fails. In The Complete Flutter Course: Build Android, iOS and Web Apps, Lesson 67 introduces RegExp, hasMatch and character ranges through DartPad. At Lesson 69, a pattern validates a contact field, with an error border shown as the user types. No lesson writes the email or phone pattern itself; that part is left to you.
How can I get the values typed into my form?
Assign a TextEditingController to each field and read its text when the value is needed, such as on Submit. At Lesson 134, The Complete Flutter Course: Build Android, iOS and Web Apps adds separate controllers to the contact fields and inspects their values with the logger package. Those controllers also provide the message for saving, and resetting the Form clears the fields after sending. The budget app's pop-ups use controllers for expense and income names and amounts too.
How can my form validate its fields together before submission?
Place the fields inside a Form assigned a GlobalKey, attach a validator to each field and call validate on the form state when Submit is pressed. This runs every validator and displays its error message, returning true only when all fields pass. The Complete Flutter Course: Build Android, iOS and Web Apps introduces this at Lesson 135, requiring first name, email and message, before saving the message to Cloud Firestore at Lesson 136.
Can my form prevent letters from being entered in a number field?
Yes. An input formatter filters keystrokes before they enter the field. At Lesson 68, The Complete Flutter Course: Build Android, iOS and Web Apps applies FilteringTextInputFormatter with a regular expression and a length limit to the contact form. The budget app's reusable field widget restricts amounts to digits at Lesson 196. Filtering blocks unwanted characters during typing, while a validator checks the completed value.
Why does sharing a GlobalKey between forms on the same screen cause an error?
A GlobalKey can identify only one widget across the app. Assigning it to Form widgets displayed together causes Flutter's duplicate GlobalKey error, leaving the key unable to identify the form you intend to validate. Each form needs a separate key. The Complete Flutter Course: Build Android, iOS and Web Apps encounters this when extracting the portfolio contact forms into shared widgets and resolves it at Lesson 151.
Does the course teach forms with dropdowns, date pickers or file uploads?
No. The Complete Flutter Course: Build Android, iOS and Web Apps covers text fields, not dropdowns, date pickers, checkboxes or file uploads, and it does not use form packages. Its text-field coverage includes borders and hints, a reusable field widget, regular expressions, input formatters, validators, a Form and GlobalKey, controllers, Cloud Firestore saving and a confirmation dialog. Other input widgets follow the same value, validator and save pattern.
Flutter
See the whole course.
The Complete Flutter Course: Build Android, iOS and Web Apps: 25 hours of video in 223 lessons, built around 9 projects, with lifetime access, a Certificate of Completion and a 14-day money-back guarantee.
The same course
For another background, goal, topic or comparison.
By background
By goal
By topic
- Dart
- State management
- Firebase
- Widgets and layouts
- UI design and styling
- Riverpod
- App architecture
- Sign-in and authentication
- Cloud Firestore
- REST APIs with Dio
- Navigation and routing
- Responsive layouts
- Animations and gestures
- Flutter web
- Set-up on Windows and Mac
- Futures and Streams
- CI with GitHub Actions
- Reusable widgets
- Debugging
- Packages from pub.dev
Comparisons
- Flutter or React Native
- Which framework to learn
- Course or free tutorials
- Flutter or native Android
- Flutter or Swift
- Flutter or Kotlin Multiplatform
- Flutter or FlutterFlow
- Learn Flutter or use AI
- Riverpod, BLoC or Provider
- Firebase or Supabase
- Flutter web or React
- Dart or JavaScript
- Flutter or Ionic
- Flutter or .NET MAUI
- VS Code or Android Studio