Complete the code to create a basic TextFormField widget.
TextFormField(
decoration: InputDecoration(
labelText: [1],
),
)The labelText property sets the label shown above the input field. It needs a string value like "Enter your name".
Complete the code to set the keyboard type for email input.
TextFormField(
keyboardType: [1],
)To show the email keyboard, use TextInputType.emailAddress.
Fix the error in the validator function to check if input is empty.
TextFormField(
validator: (value) {
if (value == null || value.[1]) {
return 'Please enter some text';
}
return null;
},
)The isEmpty property checks if the string is empty. We want to return an error if it is empty.
Fill both blanks to create a TextFormField with a controller and obscure text for passwords.
final TextEditingController _controller = TextEditingController(); TextFormField( controller: [1], obscureText: [2], )
The controller property needs the variable _controller. To hide password input, obscureText should be true.
Fill all three blanks to create a TextFormField with label, max length, and a validator that checks length > 5.
TextFormField( decoration: InputDecoration(labelText: [1]), maxLength: [2], validator: (value) { if (value != null && value.length [3] 5) { return 'Enter at least 6 characters'; } return null; }, )
The label text is "Username". The maxLength limits input to 10 characters. The validator checks if length is less than or equal to 5 using <=.