Currently I perform the validation using onChange, but my intention is that when the user moves to another text field, TextField
when it loses focus , it will be validated and show an error message if there is one.
new TextField(
controller: textController,
decoration: new InputDecoration(
hintText: 'Email',
border: InputBorder.none ,
labelText: 'Ingrese su Email',
errorText: _validate ? "Dato no valido" : null
),
keyboardType:TextInputType.emailAddress,
onChanged: (validate){
setState(() {
if (validanco(validate)) {
_validate = false;
}else _validate = true;
});
},
onEditingComplete: () =>FocusScope.of(context).requestFocus(focusnobe),
),
The method validanco()
returns a type value bool
which, if ok, returns the text true
.
Look for the documentation of FocusNode
but I did not find any method that helps me to validate when the user changes fromTtextField
What you need to do is create a
FocusNode
, assign it to your ,TextField
and add a listener to itFocusNode
to listen for focus changes.Assigning focus: