A way to completely close the keyboard without losing textfield focus - flutter

Is there a way to completely close the keyboard without losing textfield focus? I'm using textfield to capture the result provided by a physical barcode reader built into the smartphone, it's in the return value, but I want to hide the keyboard. I tried many methods, but I couldn't find a good solution.
Your final solution was the following code. However, since there is no state management in the application, the keyboard opens and closes quickly every time the page is refreshed.
#override
Widget build(BuildContext context) {
SystemChannels.textInput.invokeMethod("TextInput.hide");
return Scaffold(..

To hide the keyboard and keep the cursor visible, set readOnly to true and show the cursor to true
TextFormField(
showCursor: true,
readOnly: true),
See flutter/issues/#16863

You can set keyboardType: parameter to TextInputType.none. This will retain focus. Keep access as the TextField is still editable but no keyboard is shown.

Related

How do I make my keyboard always visible?

I'm creating a page that once the user enter, there will be a textfield which allow user to add point, is there anyway I can always allow my keyboard appear without user clicking textfield only appear?
Below images is after I click the textfield it only appear keyboard.
To give focus to a text field as soon as it’s visible, use the autofocus property.
TextField(
autofocus: true,
);
So whenever the widget appears on screen, if theres nothing else with the keyboard focus, the focus will automatically be directed to it, thus opening the keyboard.

Is there any way to push Widget above of the Keyboard when it shows up?

I uses TextFormField with Scrollable parent, when the keyboard shows up, is there any way to have the Widgets to be above the keyboard? Is it FocusNode that I should be using?
Current Situation
From this, you can see that when my keyboard shows up, the Button will be covered.
If you can, just put all widgets which needs to stay over the keyboard in a SingleChildScrollView, and set reverse property of the SingleChildScrollView to true

I don't want the keyboard to display for my Text field in Flutter

I'm building a calculator and for that I want a text field in flutter which will just give me a space where I can type but using the on screen button I have created. I don't want the keyboard to pop up I just want the cursor so that the user can edit the given text anyway possible
How to do that ?
to hide keyboard and keep the cursor visible, set readOnly to true and showCursor to true
here how :-
TextFormField(
showCursor: true,
readOnly: true),
You do not need to create a TextField, just use text and update the string of the text on each tap of the button. You can do that using StatefulWidget, it's simple. I did that.

How to show Default Android Messages like (+) button and show custom widget in place of keyboard in flutter?

How can I implement default android Messages like a custom widget in place of the keyboard shown in the GIF?
When you tap on + button, what happens is,
Keyboard Closed, to achieve this you can use FocusNode instance and assign in TextField, to unfocus or to close keyboard, you can achieve it by focusNode.unfocus().
The content you see on tap of + is outside keyboard, i.e. you have to create widget and change it's visibility accordingly, Visibility can be used.
In other case misc options is visible and user tap on keyboard icon then change visibility of extra options and obtain focus of FocusNode instance(enable keyboard), by focusNode.requestFocus().

setState blocks editing of TextEditingController

I am using a TextFormField as a widget and TextEditingController inside TextFormField for a phone number, and I am trying to validate a number while typing with the flutter_libphonenumber library, which provides an async function for validation.
I am trying to change the colour of the text depending upon validation status while entering it.
Current state:
Implemented TextFormField and providing it TextEditingController as a controller with valid initial text.
Implemented onFieldSubmitted and it works fine on tap of Done button of the keyboard.
Added listener to this controller for validation and set _isValid bool there.
I have used this bool to set colour of text inside the controller while building it.
So the current issue is, when I am entering text I get proper validated status inside the listener, but the colour of text is not changing accordingly.
I understand this is happening due to not calling setState after validation, so it will rebuild the widget and change the colour according to _isValid.
Error: When I try to setState inside the listener, it just doesn't allow editing.
Note: I have tried the same approach using onChanged method and it also does same, cannot enter or delete anything inside textField if there is pre-populated text (initialText).
Can anyone help me to solve this issue, or guide the correct path?
Thank you!
You can use the Form widget's autovalidate field by doing
Form(
autovalidate: true