当我点击表情符号图标时,表情键盘就会显示出来。但是,在没有关闭表情符号键盘的情况下,我单击textfield,文本键盘将显示在表情键盘的底部,如上面的图片所示:
我想要的是,每当表情符号键盘被显示,那么文字键盘是隐藏的。当显示文本键盘时,表情符号键盘被隐藏。
这是我的代码:
bool emojiShowing = false;
_onEmojiSelected(Emoji emoji) {
inputTextController
..text += emoji.emoji
..selection = TextSelection.fromPosition(
TextPosition(offset: inputTextController.text.length));
}
_onBackspacePressed() {
inputTextController
..text = inputTextController.text.characters.skipLast(1).toString()
..selection = TextSelection.fromPosition(
TextPosition(offset: inputTextController.text.length));
}
final _focusNode = FocusNode();
final _textFieldKey = UniqueKey();
textfield控制器:
TextEditingController inputTextController = new TextEditingController();
图标按钮代码:
IconButton(
onPressed: () {
setState(() {
emojiShowing = !emojiShowing;
if (emojiShowing) {
_focusNode.unfocus();
}
else {
FocusScope.of(context).requestFocus(_focusNode);
}
});
},
icon: Icon(
Icons.tag_faces,
color: Colors.grey,
),
),
和表情符号代码:
Offstage(
offstage: !emojiShowing,
child: SizedBox(
height: 250,
child: EmojiPicker(
onEmojiSelected: (Category category, Emoji emoji) {
_onEmojiSelected(emoji);
},
onBackspacePressed: _onBackspacePressed,
config: Config(
columns: 7,
// Issue: https://github.com/flutter/flutter/issues/28894
emojiSizeMax: 32 * (Platform.isIOS ? 1.30 : 1.0),
verticalSpacing: 0,
horizontalSpacing: 0,
initCategory: Category.SMILEYS,
bgColor: Colors.white,
indicatorColor: Colors.blue,
iconColor: Colors.grey,
iconColorSelected: Colors.blue,
progressIndicatorColor: Colors.blue,
backspaceColor: Colors.blue,
skinToneDialogBgColor: Colors.white,
skinToneIndicatorColor: Colors.grey,
enableSkinTones: true,
showRecentsTab: true,
recentsLimit: 28,
noRecentsText: 'No Recents',
noRecentsStyle: const TextStyle(
fontSize: 20, color: Colors.black26),
tabIndicatorAnimDuration: kTabScrollDuration,
categoryIcons: const CategoryIcons(),
buttonMode: ButtonMode.MATERIAL)),
),
),
还将key: _textFieldKey,
添加到TextField中。
有什么解决办法吗?
发布于 2022-02-07 07:35:18
您可以使用final _focusNode = FocusNode();
将焦点节点设置为Textfield
小部件focusNode: _focusNode,
,您可以在打开EmojiPicker时使用_focusNode.unfocus()
来松焦点,使用FocusScope.of(context).requestFocus(_focusNode);
重新获得对TextInput
的焦点。
https://stackoverflow.com/questions/71014751
复制相似问题