Coding⏱️ 2 min read📅 2026-06-03

How to Fix: How to hide soft input keyboard on flutter after clicking outside TextField/anywhere on screen?

Hide soft input keyboard on Flutter after clicking outside TextField or anywhere on screen.

Quick Answer: Use the FocusNode's focus property to track keyboard visibility and hide it when not focused.

To hide the soft input keyboard on Flutter after clicking outside of a TextField or anywhere on the screen, you can use the FocusScope widget in conjunction with the onTap method.

🛑 Solution

  • Wrap your FocusScope widget around the entire MaterialApp or the root of your widget tree.

Example:

FocusScope(  child: MaterialApp(    home: Scaffold(      body: Center(        child: TextField(          focusNode: FocusNode(),        ),      ),    ),  ),)

This will ensure that the soft keyboard is hidden when you click outside of the TextField or anywhere on the screen.

🔧 Why it works

  • The FocusScope widget provides a scope for the focus management, allowing you to manage the focus of multiple nodes in your tree.

By wrapping the entire MaterialApp or the root of your widget tree with the FocusScope widget, you can ensure that the soft keyboard is hidden when you click outside of a TextField or anywhere on the screen.

💡 Conclusion

By using the FocusScope widget, you can easily hide the soft input keyboard on Flutter after clicking outside of a TextField or anywhere on the screen.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions