Flutter: TextFormField focus if no data

Viewed 29

I have a TextFormField as follows

TextFormField(
    readOnly: true,
    validator: (v) => (v.isEmpty) ? "Required" : null,
    autovalidateMode: AutovalidateMode.onUserInteraction,
    controller: sportCenterEditingController,
    decoration: ...,
    onTap: () async {
        var t = showModalAndReturnData();    
        if (t != null) 
            sportCenterEditingController.text = sportCenters[i].name;
    }),

and even when t == null it goes to focus mode

enter image description here

how can I avoid that? If no data, I would like that it keeps to be unfocused

1 Answers

Use this code

FocusScope.of(context).unfocus();
sportCenterEditingController.clear();
Related