DavBfr / dart_barcode

Barcode generation library
https://pub.dev/packages/barcode
Apache License 2.0
132 stars 41 forks source link

BarcodeException: Unable to encode "0312341611" to ITF 14 Barcode, it is not 14 digits #12

Closed kw2019ltd closed 4 years ago

kw2019ltd commented 4 years ago

hi, iam see issues related to ITF barcode

i see for ITF need to auto complete it in case its not 14 digit , below barcode firebase_ml was able to detect

but barcode widget was not able to generate barcode widget.

https://www.free-barcode-generator.net/itf-14/ If you are enter less than 13 digits, sufficient number digit 0 is added to complete the code (13 digits).

**Non-fatal Exception: java.lang.Exception: BarcodeException: Unable to encode "**0312341611**" to ITF 14 Barcode, it is not 14 digits ` Non-fatal Exception: java.lang.Exception: BarcodeException: Unable to encode "60000351" to ITF 14 Barcode, it is not 14 digits**`

Non-fatal Exception: java.lang.Exception: BarcodeException: Unable to encode "341611" to ITF 14 Barcode, it is not 14 digits

kw2019ltd commented 4 years ago

here is example of ITF

https://favpng.com/png_view/interleaved-2-of-5-barcode-itf-14-universal-product-code-png/X8EnP87Z

image

DavBfr commented 4 years ago

I think the "0" prefixed ITF14 is a feature of this website which can be easily implemented I'm Dart whenever you need it:

var c = '123456789';
var p = c.padLeft(13, '0');
kw2019ltd commented 4 years ago

above is just example what about actual below error , firebase_ml able to scan them and identfied them as ITF 14.

Non-fatal Exception: java.lang.Exception: BarcodeException: Unable to encode "0312341611" to ITF 14 Barcode, it is not 14 digits Non-fatal Exception: java.lang.Exception: BarcodeException: Unable to encode "60000351" to ITF 14 Barcode, it is not 14 digits

Non-fatal Exception: java.lang.Exception: BarcodeException: Unable to encode "341611" to ITF 14 Barcode, it is not 14 digits

kw2019ltd commented 4 years ago

according to below , need to add check

How to calculate your check digit yourself Example barcode number: 501234576421

Step 1: add together all alternate numbers starting from the right

5 0 1 2 3 4 5 7 6 4 2 1 0 + 2 + 4 + 7 + 4 + 1 = 18 Step 2: multiply the answer by 3 18 x 3 = 54

Step 3: now add together the remaining numbers

5 0 1 2 3 4 5 7 6 4 2 1 5 + 1 + 3 + 5 + 6 + 2 = 22

Step 4: add step 2 and 3 together

54 + 22 = 76

Step 5: the difference between step 4 and the next 10th number:

76 + 4 = 80 Check digit = 4

taken from https://www.gtin.info/check-digit-calculator/

DavBfr commented 4 years ago

The checksum is correct, I don't understand what's wrong.

kw2019ltd commented 4 years ago

what is the best solution to support such barcode and display barcode widget? right now such code are failing..

DavBfr commented 4 years ago
final myCode = '123456789';

BarcodeWidget(
  barcode: Barcode.itf14(),
  data: myCode.padLeft(13, '0'),
);
kw2019ltd commented 4 years ago

this will not work see below, in case you append zeros and total digit is 14 barcode widget will fail as its not valid ITF14 as checksum is wrong 000000123456789

error with 14 digit: image

with 13 digit checksum is calculated and correct barcode generated 0000123456789

image

http://www.rasteredge.com/online-barcode-generator/itf14/

pls try it buy you self same with ITF 60000351

DavBfr commented 4 years ago

the code I gave you will padd up to 13 digits and the barcode library will calculate the checksum for you. What more do you want?

kw2019ltd commented 4 years ago

Fine by me, can't you added as part of your code?

On Tue, Jun 2, 2020, 15:03 David PHAM-VAN notifications@github.com wrote:

the code I gave you will padd up to 13 digits and the barcode library will calculate the checksum for you. What more do you want?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DavBfr/dart_barcode/issues/12#issuecomment-637495876, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALJEI6UJKXSVQC3TF5MOQHTRUTTBBANCNFSM4NQO6E2Q .

kw2019ltd commented 4 years ago

Can you do it instead the plugin?

On Tue, Jun 2, 2020, 16:51 kw 2019 ltd kw.2019.ltd@gmail.com wrote:

Fine by me, can't you added as part of your code?

On Tue, Jun 2, 2020, 15:03 David PHAM-VAN notifications@github.com wrote:

the code I gave you will padd up to 13 digits and the barcode library will calculate the checksum for you. What more do you want?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DavBfr/dart_barcode/issues/12#issuecomment-637495876, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALJEI6UJKXSVQC3TF5MOQHTRUTTBBANCNFSM4NQO6E2Q .

DavBfr commented 4 years ago

If you find that it is required in the official ITF-14 specification, yes. But if you forget a digit, prepending with a zero makes a totally different product code.

kw2019ltd commented 4 years ago

since i see alot of BarcodeException can you enhance BarcodeWidget to display redable error Text widget? like what we have in QRWidget (different plugin) QrImage( errorStateBuilder: errorStateBuilder: (cxt, err) { return Container( child: Center( child: Text( S.of(context).uhOhSomethingWentWrong, textAlign: TextAlign.center, ), ), ); },

Non-fatal Exception: java.lang.Exception: BarcodeException: Unable to encode "908001146149" to ITF 14 Barcode, it is not 14 digits

DavBfr commented 4 years ago

Yes, I can do that.

kw2019ltd commented 4 years ago

cool thanks

DavBfr commented 4 years ago

@kw2019ltd It's implemented in barcode_widget 1.3.0.

kw2019ltd commented 4 years ago

cool tnx closing ticket.

DavBfr commented 4 years ago

Don't hesitate to Buy Me A Coffee.