AmolGangadhare / flutter_barcode_scanner

Barcode scanner plugin for flutter. Supports barcode scanning for Android and iOS
https://pub.dev/packages/flutter_barcode_scanner
MIT License
382 stars 504 forks source link

Leading zeroes in barcodes are truncated #54

Closed chukwumaokere closed 4 years ago

chukwumaokere commented 4 years ago

Describe the bug Whenever I scan a barcode like this: image The result that gets printed is only the digits after the leading zeroes.

To Reproduce Steps to reproduce the behavior:

  1. Go to the barcode scanner app
  2. Scan the barcode attached
  3. Check result

Expected behavior When the barcode is scanned, the value should be 00002408, not 2408.

Smartphone (please complete the following information):

Additional context I take the value and I run these functions:

...

sBarcode(someVal) async {
  String bCode = await FlutterBarcodeScanner.scanBarcode("#ff6666", "Cancel", true);
  print(bCode);
  someVal.enterBarcode(bCode);
  return;
}
...
enterBarcode(barc) {
  flutterWebViewPlugin.evalJavascript(`document.getElementById('barcodenumber').value="${barc}";`);
  }
irperera commented 4 years ago

interesting, for me it adds a extra 0. hmm

AmolGangadhare commented 4 years ago

Hi @chukwumaokere

I've checked the barcode, it is working fine. I've tested it on iPhone 8 plus (13.2.2).

One more thing,

sBarcode(someVal) async {
  String bCode = await FlutterBarcodeScanner.scanBarcode("#ff6666", "Cancel", true);
  print(bCode);    -> What does it print?
  someVal.enterBarcode(bCode);
  return;
}

Here, in print statement what does it prints?

AmolGangadhare commented 4 years ago

@chukwumaokere

I'm not able to reproduce this issue on both Android and iOS.

Are you still facing the same issue?

chukwumaokere commented 4 years ago

I've modified my code to add the leading zeroes programatically using javascript, since all my barcodes are always 8 digits long, so right now im not necessarily "having" the issue but It would exist if I removed my workaround

AmolGangadhare commented 4 years ago

@chukwumaokere Can you post some sample code with which you are facing the issue so that I can try to reproduce this?

chukwumaokere commented 4 years ago

Im attaching it test

This is a barcode type: Interleaved2of5 Whenever I scan this barcode I expect the result to be 00002463 but I'm getting "1331" as a result

Any ideas why? I've been trying to debug this You can even test here: https://www.barcodesinc.com/generator/image.php?code=00002463&style=453&type=I25&width=300&height=125&xres=2&font=3

chukwumaokere commented 4 years ago

Nevermind I've solved the error. Instead of doing this:

sBarcode(someVal) async {
  String bCode = await FlutterBarcodeScanner.scanBarcode("#ff6666", "Cancel", true);
  print(bCode);
  someVal.enterBarcode(bCode);
  return;
}
...
enterBarcode(barc) {
  flutterWebViewPlugin.evalJavascript(`document.getElementById('barcodenumber').value="${barc}";`);
  }

Do this

sBarcode(someVal) async {
  String bCode = await FlutterBarcodeScanner.scanBarcode("#ff6666", "Cancel", true);
  print(bCode);
  someVal.enterBarcode(bCode);
  return;
}
...
enterBarcode(barc) {
    String js = "document.getElementById('barcodenumber').value='$barc'";
    flutterWebViewPlugin.evalJavascript(js);
    flutterWebViewPlugin.evalJavascript("document.getElementById('barcodenumber').dispatchEvent(event)");
  }