flutter textfield dismiss unfocus code example
Example 1: close keyboard on button click flutter
class _HomeState extends State {
var currentFocus;
unfocus() {
currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
}
Widget build(BuildContext context) {
return GestureDetector(
onTap: unfocus,
child: Scaffold(...)
)
}
Example 2: flutter unfocus textfield
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
Example 3: flutter trigger show off keyboard
FocusScope.of(context).unfocus()
Example 4: flutter unfocus textfield
FocusScope.of(context).unfocus();