Form(
// Associate the form key with this Form widget
key: _formKey,
child: Padding(
padding: EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
// Label for the name field
labelText: 'Name',
// Border style for the text field
border: OutlineInputBorder(),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.green,
width: 2.0,
), // Border color when focused
),
),
validator: (value) {
// Validation function for the name field
if (value!.isEmpty) {
// Return an error message if the name is empty
return 'Please enter your name.';
}
// Return null if the name is valid
return null;
},
onSaved: (value) {
// Save the entered name
_name = value!;
},
),
SizedBox(height: 20.0),
TextFormField(
decoration: InputDecoration(
// Label for the email field
labelText: 'Email',
// Border style for the text field
border:
OutlineInputBorder(),
// Border color when focused
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.green,
width: 2.0,
),
),
),
validator: (value) {
// Validation function for the email field
if (value!.isEmpty) {
// Return an error message if the email is empty
return 'Please enter your email.';
}
// You can add more complex validation logic here
return null; // Return null if the email is valid
},
onSaved: (value) {
// Save the entered email
_email = value!;
},
),
SizedBox(height: 20.0),
ElevatedButton(
style: ElevatedButton.styleFrom(
// Button background color
backgroundColor: Colors.green,
// Button text color
foregroundColor: Colors.white,
),
// Call the _submitForm function when the button is pressed
onPressed: _submitForm,
// Text on the button
child: Text('Submit'),
),
],
),
),
),