我无法控制键盘显示或隐藏,在我的项目中,我需要始终隐藏键盘,但要专注于显示我的自定义键盘(小部件)。
需要帮忙!!!
这是我想要的
这是我的问题
插入NoKeyboardEditableText
而不是你的TextField
class NoKeyboardEditableText extends EditableText {
NoKeyboardEditableText({
@required TextEditingController controller,
TextStyle style = const TextStyle(),
Color cursorColor = Colors.black,
bool autofocus = false,
Color selectionColor
}):super(
controller: controller,
focusNode: NoKeyboardEditableTextFocusNode(),
style: style,
cursorColor: cursorColor,
autofocus: autofocus,
selectionColor: selectionColor,
backgroundCursorColor: Colors.black
);
@override
EditableTextState createState() {
return NoKeyboardEditableTextState();
}
}
class NoKeyboardEditableTextState extends EditableTextState {
@override
Widget build(BuildContext context) {
Widget widget = super.build(context);
return Container(
decoration: UnderlineTabIndicator(borderSide: BorderSide(color: Colors.blueGrey)),
child: widget,
);
}
@override
void requestKeyboard() {
super.requestKeyboard();
//hide keyboard
SystemChannels.textInput.invokeMethod('TextInput.hide');
}
}
class NoKeyboardEditableTextFocusNode extends FocusNode {
@override
bool consumeKeyboardToken() {
// prevents keyboard from showing on first focus
return false;
}
}
您可以使用自定义focusNode
这可以防止键盘仅在第一次点击时出现:
TextField(focusNode: FirstDisabledFocusNode(),)
class FirstDisabledFocusNode extends FocusNode {
@override
bool consumeKeyboardToken() {
return false;
}
}
这可以防止:
TextField(focusNode: AlwaysDisabledFocusNode())
class AlwaysDisabledFocusNode extends FocusNode {
@override
bool get hasFocus => false;
}