How to disable predictive text in TextField of Flutter? - flutter

I want to disable predictive text which comes in the keyboard of a textfield. It is not so difficult in native android and IOS but I have not found a solution in a Flutter.
I have tried using autocorrect: false and changing keyboardtypes but it is not working.
TextField(
autocorrect: false,
keyboardType: TextInputType.emailAddress,
decoration: new InputDecoration(hintText: "Enter text"),
autofocus: true,
),

If neither enableSuggestions nor autocorrect can solve the problem, try setting keyboardType to TextInputType.visiblePassword.

You can try to add enableSuggestions = false to your textfield widget. This should disable the predictive text from your keyboard as supposed to https://github.com/flutter/flutter/pull/42550.
TextField(
autocorrect: false,
enableSuggestions: false,
keyboardType: TextInputType.emailAddress,
decoration: new InputDecoration(hintText: "Enter text"),
autofocus: true,
),

At the time of writing this answer, this is not yet available in Android. But using autocorrect: false on iOS should work fine.
Check: https://github.com/flutter/flutter/issues/22828

This worked for me on both iOS and android
TextField(
autocorrect: false,
obscureText: true,
controller: answerText,
textAlign: TextAlign.center,
keyboardType: TextInputType.text,
textInputAction: TextInputAction.done,
autofocus: true,
onChanged: (value) {
setState(() {
result = value;
});
},),
The only downside is that it obscure from the screen what is written. A workaround is to add somewhere in the screen Text(result)

Related

How to display keyboard with only numbers?

I want to display keyboard with only numbers, not Operators or any other symbols in keyboard.
I tried filter output already using inputFormatters in textfield.
You will need to add inputFormatters & keyboardType properties to enable keyboard with number inputs only to your TextField widget.
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly,
],
keyboardType: TextInputType.number,
if its in a TextField use this :
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
or you can use this :
keyboardType: TextInputType.phone,
also you can check this package
check this package numeric_keyboard
Use keyboardType property of TextField
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly
],
Here keyboardType is number so it will accept only number,
inputFormatters will format your input what you are typing.
TextField(
keyboardType: TextInputType.number,
inputFormatters:<TextInputFormatter>.
[FilteringTextInputFormatter.digitsOnly]
decoration:InputDecoration(labelText: 'Number')
),
just use this code.
TextFormField(
keyboardType: TextInputType.numberWithOptions(
signed: true, decimal: true),
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
)

Flutter AutofillHints oneTimeCode doesn't work

I want to catch OTP sms code but it doesn't work on IOS.
I need show the code upper of keyboard.
my code block is;
TextField(
controller: controller,
autofillHints: const <String>[AutofillHints.oneTimeCode],
keyboardType: TextInputType.number,
onChanged: onChanged,
),
From Flutter docs at https://master-api.flutter.dev/flutter/material/TextField/autofillHints.html "Some autofill hints only work with specific keyboardTypes". Try changing the keyboardType. For example:
TextField(
controller: controller,
autofillHints: const <String>[AutofillHints.oneTimeCode],
keyboardType: TextInputType.text,
onChanged: onChanged,
),

Flutter : external barcode scanner continuous

I am developing a flutter application with below process
scan number (external Bluetooth barcode scanner)
upload barcode data
repeat 1,2 step c
I could able to scan and upload the first data. then I cleared the text. but i could not place the cursor at the _text controller.
I dont want to press the text field every time before scan the textfield.
TextField(
controller: _text,
textInputAction: TextInputAction.go,
onSubmitted: (value) {
print(submit online using function");
_text.clear();
_text.selection= TextSelection.collapsed(offset: -1);
},
decoration: const InputDecoration(
icon: Icon(Icons.person),
hintText: 'Enter ID',
labelText: 'Enter ID',
),
autofocus: true,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly
],
),
TextFormField(
enabled: true,
autofocus: true,
autocorrect: false,
textInputAction: TextInputAction.done,
keyboardType: TextInputType.text,
focusNode: focusBarCode,
onFieldSubmitted: (val) {
print(val); // the scan value
//process the val
barCodecontroller.text =""; // set to blank again
focusBarCode.requestFocus();//set focus again, so u can
//scan again
`enter code here`},
controller: barCodecontroller,
),

How can i TextField show cursor always

I want show cursor always in textfield but i couldn't see a solution.
What I want to do is always show the cursor like whatsapp.
I want the cursor to appear even if the keyboard is closed
TextField(
textCapitalization:TextCapitalization.sentences,
minLines: 1,
maxLines: 6,
controller: _textEditingController,
focusNode: _focusNode,
)
TextField(
textCapitalization:TextCapitalization.sentences,
minLines: 1,
maxLines: 6,
autofocus: true, // line Added
controller: _textEditingController,
focusNode: _focusNode,
)

how to make can a TextField content's type can be number and letter if obscureText property is true

using a TextField and its obscureText property is true, how can I input some letter, now only the number can be input
obscureText:true,
textInputFormatter: WhitelistingTextInputFormatter(RegExp("[a-zA-Z0-9]"))
I want to make the TextField's input can be both letters and numbers
The obscureText property should not matter.
If you want to input letters and numbers,
then you have to use the keyboardType property.
For example:
keyboardType: TextInputType.text
BR
keyboardType: TextInputType.emailAddress,
TextFormField(
textInputAction: TextInputAction.next,
focusNode: secondFocusNode,
keyboardType: TextInputType.emailAddress,
controller: emailController,
),