Flutter AutofillHints oneTimeCode doesn't work - flutter

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,
),

Related

How to include plus symbol to a numeric keyboard

I was wondering how to implement in my application a TextFormField with a numeric keyboard that includes the plus("+") with the intention of including of facilitating the user to input international phone numbers.
TextFormField(
controller: phoneNumberController,
keyboardType: TextInputType.number, // Fix to include plus symbol
),
change type TextInputType.number at TextInputType.phone
TextFormField(
controller: phoneNumberController,
keyboardType: TextInputType.phone, // Fix to include plus symbol
),

Remove error message in TextFormField in Flutter

Hi I want to remove error message caused by validator in TextFormField widget after I submit a form in flutter.
Ps : I want the error message disappeared after I select again the TextFormField to write into it again.
TextFormField(
controller: _emailController,
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
validator: (value) {
if (value == null ||
value.isEmpty ||
!EmailValidator.validate(value)) {
return nullEmailMsg;
}
return null;
},
decoration: InputDecoration(
hintText: emailHint,
prefixIcon: Icon(Icons.mail),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
If you put your TextFormField inside a Form with the property autovalidateMode: AutovalidateMode.onUserInteraction, the validation function should trigger when you select again or change the text.
If the validation function is satisfied, the error message will be removed.
You have to use the autoValidateMode method in TextFormField.
Here, is the some of the reference:
https://api.flutter.dev/flutter/widgets/AutovalidateMode-class.html

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,
),

Respond to 'done' button in TextFormField

I want to respond to the user pressing the 'done' button on their keyboard when typing in a TextFormField.
Code so far:
TextFormField(
autofocus: true,
textInputAction: TextInputAction.done,
decoration: InputDecoration(
labelText: 'ENTER YOUR TASK'
),
),
use onFieldSubmitted or onEditingComplete property.
onEditingComplete
When a completion action is pressed, such as "done", "go", "send", or "search", the user's content is submitted to the controller and then focus is given up.
When a non-completion action is pressed, such as "next" or "previous", the user's content is submitted to the controller, but focus is not given up because developers may want to immediately move focus to another input widget within onSubmitted.
Example,
TextFormField(
onEditingComplete: (){
//do your stuff
},
)
onFieldSubmitted
onSubmitted is called when the user indicates that they are done editing the text in the field.
Example,
TextFormField(
onFieldSubmitted: (val){
// process
},
)
TextEditingController _textEditingController = new TextEditingController();
TextFormField(
controller: _textEditingController,
autofocus: true,
textInputAction: TextInputAction.done,
onEditingComplete: () {
FocusScope.of(context).requestFocus(new FocusNode());
print(_textEditingController.text);
//TODO your Response code for user
},
decoration: InputDecoration(labelText: 'ENTER YOUR TASK'),
),

How to disable predictive text in TextField of 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)