Flutter : external barcode scanner continuous - flutter

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

Related

How to make sure textformfield input is a number(positive or negative or double)

Hi im facing the issue when converting user input to a double example when i input -3 i faced with an FormatException (FormatException: Invalid double -). How can i deal with this? Furthermore how can i prevent user from entering 2 - or . ( 3.3.3 or 3- or --3)as this will also cause error with the double.parse(). Thanks in advance!
TextFormField(
inputFormatters: [FilteringTextInputFormatter.allow(RegExp('[0-9.-]')),],
keyboardType: TextInputType.number,
onChanged:(value) {
setState(() {
fieldPointX = double.parse(value);
});
},
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'X'
),
),
try using this regExp in your TextFormField widget
TextFormField(
keyboardType: const TextInputType.numberWithOptions(
signed: true,
decimal: true,
),
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(r'^-?\d*.?\d*')),
],
),

I want to delete this field from the flutter application, what should I do?

Here is the code that I want to delete the field from -
setPincode() {
return TextFormField(
keyboardType: TextInputType.number,
controller: pincodeC,
readOnly: true,
style: Theme.of(context)
.textTheme
.subtitle2
.copyWith(color: colors.fontColor),
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
onSaved: (String value) {
pincode = value;
},
validator: (val) =>
validatePincode(val, getTranslated(context, 'PIN_REQUIRED')),
decoration: InputDecoration(
hintText: getTranslated(context, 'PINCODEHINT_LBL'),
isDense: true,
),
);
}
Or you can see in this image what I want to remove
You are calling a function called setPincode that returns this TextFormField. Don't call setPincode if you no longer need it.

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

Sanitize TextFormField value before validation in flutter

I want to use do some sanitization like trimming a string before the validator function is called. I don't want to do it in the onChange method but wait until the user finsehes his input.
TextFormField(
decoration: InputDecoration(
labelText: 'Email*', hintText: "john.doe#gmail.com"),
keyboardType: TextInputType.emailAddress,
validator: emailValidator,
onChanged: (String str) {
}
),

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)