I created form when i click on button to validate validator not showing error.
GlobalKey<FormState> formkey= GlobalKey<FormState>();
Created Global Key in my code
Form(
key: formkey,
child: ListView(
scrollDirection: Axis.vertical,
children: [
Padding(
padding: const EdgeInsets.all(20),
child: TextFormField(
controller: _name,
validator: (value) {
if (value == null || value == value.isEmpty) {
return "Enter Name";
}
return null;
},
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(),
focusedBorder: OutlineInputBorder(),
labelText: "Name",
prefixIcon: Icon(Icons.person),
errorStyle: TextStyle(color: Colors.red)),
),
),
I created form
Center(
child: ElevatedButton(
onPressed: () {
if (formkey.currentState!.validate()) {
setState(() {
name = _name.text;
email = _email.text;
password = _password.text;
});
addUser();
clear();
}
},
child: Text("Register"))),
Code of button
This is the code help me.
2
Answers
remove value == from the condition it will work.
write like this
I solved your answer like this: