Search code snippets, questions, articles...

Remove focus from TextField on button click in Flutter

If you have a button created using Flutter and you want to remove the focus from the TextField widget using the button click or tap then you can use the below code on the button tap event in Flutter.
onTap: () {
    WidgetsBinding.instance.focusManager.primaryFocus?.unfocus();
}

The code can be used to remove focus from a text field on button click used in the Flutter app. You can use it if you want to unfocus from the current element on button tap method. 

Was this helpful?
1 Comments

Thankyou so much for your help, this solved my issue which was active from a month now. 

Programming Feeds
Learn something new everyday on Devsheet