Custom form validation
Now that we have covered how to use the Form
and FormField
widgets to reduce some of the boilerplate of handling user input, let’s round out our form with new input fields to capture the contact’s phone number and email address.
In the contact_edit_view.dart
module, add a TextEditingController
for the email address and phone number, and then instantiate them in the initState
method. The result should resemble the following code:
late final TextEditingController _firstNameController; late final TextEditingController _lastNameController; late final TextEditingController _emailController; late final TextEditingController _phoneController; @override void initState() { super.initState(); _firstNameController = TextEditingController(text: _contact?.firstName); _lastNameController = ...