Reputation: 413
I can't control keyboard show or hide, In my project I need to always hide keyboard but keep focused to display my custom keyboard(a widget).
This is I want
And this is my problem
Upvotes: 41
Views: 74347
Reputation: 11
TextField(
obscureText: true, // Mask the input text
keyboardType: TextInputType.emailAddress, //make it emailAddress type
)
make keyboardtype as emailAddress, this will avoid phone pop up secure keyboard
Upvotes: 0
Reputation: 403
FYI, TextInputType.none was introduced in #83974:
TextField( keyboardType: TextInputType.none, ... )
Upvotes: 28
Reputation: 282
try use input_with_keyboard_control
package
It helped me solve my problem, of receiving the text from a barcode scanner, without showing the keyboard
Upvotes: 1
Reputation: 1569
To hide keyboard and keep the cursor visible, set readOnly
to true
and showCursor
to true
.
TextFormField(
showCursor: true,
readOnly: true),
Upvotes: 97
Reputation:
You can use custom focusNode
This prevents keyboard appearing only on first tap:
TextField(focusNode: FirstDisabledFocusNode(),)
class FirstDisabledFocusNode extends FocusNode {
@override
bool consumeKeyboardToken() {
return false;
}
}
This prevents always:
TextField(focusNode: AlwaysDisabledFocusNode())
class AlwaysDisabledFocusNode extends FocusNode {
@override
bool get hasFocus => false;
}
Upvotes: 12
Reputation: 29438
Insert NoKeyboardEditableText
instead your 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;
}
}
Upvotes: 4