Cycle through input fields and keep keyboard open - flutter

I have a form with multiple text fields and would like users to be able to jump to the next input field when tapping "enter" on the on-screen keyboard.
I have been able to make it work by requesting focus for the next field's FocusNode in my field's onFieldSubmitted handler:
new TextFormField(
...
onFieldSubmitted: (newValue) {
...
FocusScope.of(context).requestFocus(
widget.nextNode ?? new FocusNode()
);
}
This works, but you do briefly see the on-screen keyboard close and re-open. Is there a way in Flutter to keep the keyboard on the screen until widget.nextNode becomes null?

Try adding below parameter to TextFormField.
textInputAction: TextInputAction.next,

Related

Flutter focus textfield without opening softkeyboard?

I'm getting input to my textfield from barcode scanner so I dont need softkeyboard to open when textfield in focus.To achieve that I tried TextInputType.none it hides the keyboard but also can't receive input from scanner.
TextField(
keyboardType: TextInputType.none,
controller: loginTextController,
focusNode: _loginTextfieldFocus,
decoration: decoration(context,loginTextController),
onChanged: (s){
if(s.contains('\n')||s.contains('\r')){
Log.d("Enter event found");
}
},
),
I also tried SystemChannels.textInput.invokeMethod('TextInput.hide'); but it hides only first time. Whenever a character added in textfield softkeyboard becomes visible.

Show textcursor before tapping

I'm using the TextField widget as a text input for my app. The text cursor starts blinking after I tap the TextField and doesn't stop blinking. What I would like to do is have the text cursor blink all the time. How do I have the text cursor start blinking before I even tap/activate it?
You can use autofocus:
TextField(
autofocus : true,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Name',
),
)
Whether this text field should focus itself if nothing else is already focused.
If true, the keyboard will open as soon as this text field obtains focus. Otherwise, the keyboard is only shown after the user taps the text field.
Defaults to false. Cannot be null.

TextFormField ignores any text change after picking image

I've been scratching my head on this. Perhaps someone can help.
I have a statefull widget with a TextFormField and a button that calls the ImagePicker.pickImage function.
When I write something in the textformInput and then click on the select image button, when the image select returns from the picking, the textformfield has the text before I wrote.
It seems the onChanged function is never called when I press the button, so I cannot update my model variable.
I also tried to listen for focus out event on the textformfield widget but it also doesnt get called.
What am I missing? Any tip would be great.
Thanks
TextFormField(
keyboardType: TextInputType.multiline,
maxLines: 5,
controller: _observationsFieldController,
onChanged: (String value) {
onFieldChanged(_observationsFieldController, value);
widget.user_file.observations = value;
},
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(horizontal:10, vertical: 2),
hintText: 'Observations',
suffix: clearSuffix(_observationsFieldController),
),
),
Have you tried using setState()? Since you are updating the state, it might work when you call set state.

How to show the Keyboard automatically for a Textfield in Flutter

I have a TextField in Flutter of which I want to automatically select the text and show the keyboard.
I can select the text through a TextEditingController, but even with a FocusNodes requestFocus the keyboard isn't shown, when the Widget opens.
How to automatically open the keyboard for a TextField?
You can use the autofocus:true property of the TextField:
Whether this text field should focus itself if nothing else is already focused.
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.
TextField(TextEditingController: controller,
focusNode: focusNode,
autofocus:true)
You can set the autofocus property on TextField to true:
TextField(
autofocus: true,
);
Hope it helps!
class yourWidget extends StatelessWidget {
FocusNode inputNode = FocusNode();
// to open keyboard call this function;
void openKeyboard(){
FocusScope.of(context).requestFocus(inputNode)
}
#override
Widget build(BuildContext context) {
TextFormField(
//assign the node like this
focusNode: inputNode,
autofocus:true,)
}
I have done this just using:
autofocus: true,
But if you want more control over your TextField / TextFormFeild keyboard you can use:
1. First declare a focus node object:
FocusNode focusNode = FocusNode(); // declear a focusNode object
2. On TextFeild / TextFormFeild, just do like below:
focusNode: focusNode, // assign focusNode object on focusNode value
autofocus: true, // make autofocus true for first auto open keyboard
3. Just call this function when you want to open your keyboard:
void openKeyboard () {
FocusScope.of(context).requestFocus(inputNode);
}
This is an example of how you can use it. Using that format you can open the keyboard automatically / you have complete control over whether or not you need to open the keyboard.
I hope this will fix your issue.

Show pulsing cursor but do not open the keyboard when textfield is initialized

I don't want the keyboard to automatically appear when I'm pressing on the widget. However, I want to show the cursor to indicate that there's a textfield in this area. How can I achieve this?
I can only think of one workaround for this. You can add FocusNode to your field and listen to changes. When the field get focus, hide the keyboard.
final FocusNode fn = FocusNode();
fn.addListener(() {
// You can control here whether or not you want to hide automatically shown keyboard
if (fn.hasFocus) {
// Hiding the keyboard
SystemChannels.textInput.invokeMethod('TextInput.hide');
}
});
...
// Pass the focus node to text field:
TextField(
focusNode: fn
);
I haven't tested it, though.