I am using an onChange
method in a TextFormField
widget... but is there a onLeave
function on another parent widget.... I looked into GestureDetector
but they also don't have it
TextFormField(
controller: _emailAddress_controller,
keyboardType: TextInputType.emailAddress,
validator: validateEmail,
onChanged: (value) {
print(validateEmail(_emailAddress_controller.toString()));
},
)
We don't have onLeave() but we surely do have onFieldSubmitted() for TextFormField(). It triggers some code when the user presses submit on the right-hand corner of the keyboard.
I'm assuming you want to move the focus on to a different textfield when the user leaves first textfield so you can use FocusNodes.
FocusNode _secondFieldFocusNode = FocusNode(); //declaration
//on the first field's onFieldSubmitted Fn, let's put some code.
TextFormField(
onFieldSubmitted: (value) {
FocusScope.of(context).requestFocus(_secondFieldFocusNode),
),
//assign the focus node to second field
TextFormField(
focusNode: _secondFieldFocusNode,
)