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.
Thankyou so much for your help, this solved my issue which was active from a month now.