Я пытался добавить автоматическую проверку отсканированного штрих-кода. Моя проблема в том, что когда я ввожу штрих-код вручную, система проверяет правильность. Если я использую камеру для считывания штрих-кода, система не проверяет значение автоматически. На экране будет отображаться весь штрих-код, если я немного отредактировал текст после проверки. Я пытался добавить CR к строковому значению, но это тоже не сработало. Мой фрагмент кода ниже. Кто-нибудь может мне помочь, пожалуйста.
// BARCODE SCANNER
Future<String> scanBarcodeNormal() async {
String barcodeScanRes;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
barcodeScanRes = await FlutterBarcodeScanner.scanBarcode(
"#ff6666", "Cancel", true, ScanMode.BARCODE);
print(barcodeScanRes);
} on PlatformException {
barcodeScanRes = 'Failed to get platform version.';
}
if (!mounted) return null;
return barcodeScanRes;
}
// TEXT FORM
TextFormField(
maxLines: null,
autovalidate: true,
autofocus: true,
textAlign: TextAlign.justify,
controller: barcodeController,
autocorrect: false,
decoration: InputDecoration(
prefixText: " Barcode : ",
hintText: 'Scan or Enter Barcode',
filled: true,
fillColor: Color(0xFFDBEDFF),
contentPadding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
borderSide: BorderSide(color: Colors.green),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
borderSide: BorderSide(color: Colors.red),
),
),
onChanged: (value) {
getBarcode(value);
},
)
// TEXT FORM
void getBarcode(String scanBarcode) async{
Barcode data = await(searchSingleBarcode(scanBarcode));
if(data != null) {
setState(() {
itemCodeController.text = data.itemCode;
itemNameController.text = data.description;
itemNRetailController.text = data.retail;
itemNStockController.text = data.qty;
itemNPackController.text = data.packId;
itemTypeController.text = "Stock";
});
}
else{
itemCodeController.text = ' No Data Exists ';
itemNameController.clear();
itemNRetailController.clear();
itemNStockController.clear();
itemNPackController.clear();
itemTypeController.clear();
}
}
}