I have the following code which either opens the keyboard and closes another custom widget or opens the custom widget and closes the keyboard.
The showCustomTab variable controls when to open that custom widget.
The problem I have is that when the keyboard is opened (so the showCustomTab is set to false) and I click the icon, the custom tab opens faster than the keyboard closes therefore, for a split second, I have a screen overflow because both the keyboard and the custom are showed (not visible with human eye but still throws overflow error).
So the problem I have is when switching between keyboard and custom widget. When the custom widget is shown and I open the keyboard this doesn't happen so only the other way around.
I've added that extra unfocus
if (chatFocusNode.hasFocus) {
chatFocusNode.unfocus();
}
section before showCustomTab = !showCustomTab; but still I couldn't make it work.
Below is the full code:
GestureDetector(
onTap: () {
setState(
() {
menuProvider.closeAll();
if (chatFocusNode.hasFocus) {
chatFocusNode.unfocus();
}
cursorPosition = chatTextEditingController.selection;
showCustomTab = !showCustomTab;
if (showCustomTab) {
FocusScope.of(context).requestFocus(unUsed);
} else {
FocusScope.of(context).requestFocus(chatFocusNode);
}
},
);
},
child: Icon(
showCustomTab ? Icons.keyboard : Icons.insert_emoticon,
color: showCustomTab
? Theme.of(context).accentColor
: Colors.black87,
size: 30,
),
),
I've tried to manually close the keyboard (from the android emulator) then open the custom tab and it works so I know this is where I have the bug. Tried a bunch of things but couldn't make it work.