I have textformfields in my form. When I click on submit button the validation error displays under the textformfield. I want to add focus to that particular field so when user clicks on save button the field pops up. user should not need to scroll up and type the info. User should be able to directly start typing. In current scenario user gets confused and is unaware of why save button didnt work. Bcoz until scrolled up the error is unknown.
TextFormField(
controller: NoteController,
validator: (String value){
if(value.isEmpty)
{
return "Note can't be null";
}
else
return null;
},
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: const BorderSide(width: 2.0),)),
keyboardType: TextInputType.multiline,
minLines: 5,
maxLines: 5,
onChanged: (value) {
this.note.note = value;
},
),
bool validateAndSave() {
final form = globalFormKey.currentState;
if (form.validate()) {
form.save();
return true;
}
return false;
}
void _save() async {
if (validateAndSave()) {
}
}