Live Form Validation in Flutter

Validate Form while changing the value of TextFormFields

Yash Anghan
1 min readJul 15, 2023

When we have so many form in one page and it’s swipe by continue or skip button at that time If form is not validate but Button color and it’s click event must be deactivated by the changing the values if all Formfields are validated and button must be automaticaly activeted to go next page so that at that situation flutter gives a functionality in Form Widget which is “onChanged” in this Function we got identify that somewhere form values are being changed.

Form(
key: FormKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
onChanged: () {
// functions which are called by values changes in the Form
if(Formkey.currentState!.validate()){
validateButton=true;
}else{
validateButton=false;
}
},
)

shown above code shows that onChanged method will called by the values changes in the Form and “autovalidateMode” is similar but it’s only validate the Form.

In onChnaged method we can command or pass values to other varibales like above code shows that true or false values are given to “validateButton” varibable to activate or deactivate button at the end of the page.

--

--