2

I am developing a flutter application with below process

  1. scan number (external Bluetooth barcode scanner)
  2. upload barcode data
  3. 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 ], ), 
5
  • what plugin are you using to get data from the external barcode scanner? Commented Jul 7, 2021 at 12:58
  • we don't use any plugins for the external barcode scanners. Android detects as some keyboard. Commented Jul 8, 2021 at 9:01
  • oh, I can't even manage to connect the device via bluetooth, would you mind sharing the code to connect the scanner with your flutter app? Commented Jul 8, 2021 at 9:14
  • Is the device connected physically to the phone? Commented Jul 8, 2021 at 9:42
  • If you have a device with a USB you can connect via OTG. if BT, Just pair it. it will work. the below code(mokth) will just work fine. if the continues is too fast, just increase the time( for that, the manufacturer would give a settings barcode ). Commented Jul 9, 2021 at 7:14

2 Answers 2

2
 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, ), 
Sign up to request clarification or add additional context in comments.

Comments

1

the external bar code scanner works like this: The very first field on your UI will get clicked or what so ever..so make sure you place the field in your layout at the top...so when the barcode data enters the field all you have to do is clear the field and reset the focus on the very on the field(edittext).. it is more advisable to use edit text in these cases.Also try to use looper with delay upto 1.5 secs to clear the text in edit text.

// Define the TextEditingController final TextEditingController barcodeTextController = TextEditingController(); EditText( autofocus: true, keyboardType: TextInputType.text, focusNode: focusBarCode, onSubmitted: (val) async { print(val); // the scan value await Future.delayed(Duration(milliseconds: 1500)); // Delay for 1.5 seconds barCodeController.clear(); // Clear the text focusBarCode.requestFocus(); // Set focus again for the next scan }, controller: barCodeController, ), 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.