I have a registration form with multiple text feilds and a Radio button and a birthdate picker. I want to disable the submit button untill the user key in all the required feilds.
I managed to do something but it only validates one text feild.
bool activateTheButton =false;
@override
initState(){
super.initState();
nameController = TextEditingController();
nameController.addListener(() {
final activateTheButton = nameController.text.isNotEmpty;
setState(() => this.activateTheButton = activateTheButton);
......................
ElevatedButton( onPressed: activateTheButton
? (){
}: null,
}
How can I make it so that all the textfeilds along with the radio button and date of birth must have data first then activate button?
your help is highly appreciated.
3
Answers
Take a look here How do I disable a Button in Flutter?
In the same way you should enable it when you wanto to.
Have a variable that enables/disables the button:
Use
IgnorePointer
andOpacity
for the button:You are going to have controllers for each TextFields;
Use the
TextField
‘sonChanged: (value) {}
to call a method that handles the_disabled
variable:check this hope this helps
How to disable button until text form field has valid data Flutter