From 4d389591e9f07ce1e0a3fa526c894680fcf800a0 Mon Sep 17 00:00:00 2001 From: David PHAM-VAN Date: Fri, 5 Jan 2024 07:48:51 -0400 Subject: [PATCH] Fix format and update dev dependencies --- barcode/lib/src/upce.dart | 86 ++++++++++++++++++------------------- barcode/pubspec.yaml | 2 +- barcode/test/upce_test.dart | 3 +- 3 files changed, 43 insertions(+), 48 deletions(-) diff --git a/barcode/lib/src/upce.dart b/barcode/lib/src/upce.dart index 50b3742..f3a859c 100644 --- a/barcode/lib/src/upce.dart +++ b/barcode/lib/src/upce.dart @@ -72,9 +72,8 @@ class BarcodeUpcE extends BarcodeEan { /// Convert an UPC-A barcode to a short version UPC-E String upcaToUpce(String data) { - //Basic checking of string headers and lengths. - if ( RegExp(r'^[01]\d{11}$').firstMatch(data) == null) { + if (RegExp(r'^[01]\d{11}$').firstMatch(data) == null) { throw BarcodeException('Unable to convert "$data" to $name Barcode'); } //Refer to https://en.wikipedia.org/wiki/Universal_Product_Code#UPC-E @@ -83,34 +82,31 @@ class BarcodeUpcE extends BarcodeEan { //Algorithm 2: https://www.keepautomation.com/upca/upca-to-upce-conversion.html // Algorithm 1=> - final mc = data.substring(1,6); //manufacturer code - final pc = data.substring(6,11); //product code + final mc = data.substring(1, 6); //manufacturer code + final pc = data.substring(6, 11); //product code - if(['000', '100', '200'].contains(mc.substring(mc.length - 3)) && int.parse(pc) <= 999){ + if (['000', '100', '200'].contains(mc.substring(mc.length - 3)) && + int.parse(pc) <= 999) { //if manufacturer_code[-3:] in ["000", "100", "200"] and int(product_code) <= 999: // upce = manufacturer_code[:2] + product_code[-3:] + manufacturer_code[2] - return '${mc.substring(0,2)}${pc.substring(pc.length-3)}${mc[2]}'; - } - else if(mc.substring(mc.length - 2) == '00' && int.parse(pc) <= 99){ + return '${mc.substring(0, 2)}${pc.substring(pc.length - 3)}${mc[2]}'; + } else if (mc.substring(mc.length - 2) == '00' && int.parse(pc) <= 99) { //elif manufacturer_code[-2:] == '00' and int(product_code) <= 99: // upce = manufacturer_code[:3] + product_code[-2:] + "3" - return '${mc.substring(0,3)}${pc.substring(pc.length-2)}3'; - } - else if(mc.substring(mc.length - 1) == '0' && int.parse(pc) <= 9){ + return '${mc.substring(0, 3)}${pc.substring(pc.length - 2)}3'; + } else if (mc.substring(mc.length - 1) == '0' && int.parse(pc) <= 9) { //elif manufacturer_code[-1] == "0" and int(product_code) <= 9: // upce = manufacturer_code[:4] + product_code[-1] + "4" - return '${mc.substring(0,4)}${pc.substring(pc.length-1)}4'; - } - else if(mc.substring(mc.length - 1) != '0' && [5, 6, 7, 8, 9].contains(int.parse(pc))){ + return '${mc.substring(0, 4)}${pc.substring(pc.length - 1)}4'; + } else if (mc.substring(mc.length - 1) != '0' && + [5, 6, 7, 8, 9].contains(int.parse(pc))) { //elif manufacturer_code[-1] != "0" and int(product_code) in [5,6,7,8,9]: // upce = manufacturer_code + product_code[-1] - return mc + pc.substring(pc.length-1); - } - else { + return mc + pc.substring(pc.length - 1); + } else { throw BarcodeException('Unable to convert "$data" to $name Barcode'); } - // Algorithm 2=> /* if([0x35, 0x36, 0x37, 0x38, 0x39].contains(data.codeUnits[10]) && data.substring(6,10) == '0000' && data[5] != '0') { @@ -248,12 +244,12 @@ class BarcodeUpcE extends BarcodeEan { @override double marginLeft( - bool drawText, - double width, - double height, - double fontHeight, - double textPadding, - ) { + bool drawText, + double width, + double height, + double fontHeight, + double textPadding, + ) { if (!drawText) { return 0; } @@ -263,12 +259,12 @@ class BarcodeUpcE extends BarcodeEan { @override double marginRight( - bool drawText, - double width, - double height, - double fontHeight, - double textPadding, - ) { + bool drawText, + double width, + double height, + double fontHeight, + double textPadding, + ) { if (!drawText) { return 0; } @@ -278,14 +274,14 @@ class BarcodeUpcE extends BarcodeEan { @override double getHeight( - int index, - int count, - double width, - double height, - double fontHeight, - double textPadding, - bool drawText, - ) { + int index, + int count, + double width, + double height, + double fontHeight, + double textPadding, + bool drawText, + ) { if (!drawText) { return super.getHeight( index, @@ -309,13 +305,13 @@ class BarcodeUpcE extends BarcodeEan { @override Iterable makeText( - String data, - double width, - double height, - double fontHeight, - double textPadding, - double lineWidth, - ) sync* { + String data, + double width, + double height, + double fontHeight, + double textPadding, + double lineWidth, + ) sync* { if (data.length <= 8) { // Try to convert UPC-E to UPC-A data = upceToUpca(data); diff --git a/barcode/pubspec.yaml b/barcode/pubspec.yaml index 5917fbc..21bda48 100644 --- a/barcode/pubspec.yaml +++ b/barcode/pubspec.yaml @@ -16,5 +16,5 @@ dependencies: dev_dependencies: convert: ^3.0.1 - flutter_lints: ^2.0.1 + flutter_lints: ^3.0.1 test: ^1.19.0 diff --git a/barcode/test/upce_test.dart b/barcode/test/upce_test.dart index 61889c9..1e6560c 100644 --- a/barcode/test/upce_test.dart +++ b/barcode/test/upce_test.dart @@ -68,7 +68,7 @@ void main() { }); test('Barcode UPC-E normalize (fallback)', () { - final bc = Barcode.upcE( fallback: true); + final bc = Barcode.upcE(fallback: true); if (bc is BarcodeUpcE) { expect(bc.normalize('18740000015'), equals('18741538')); expect(bc.normalize('48347295752'), equals('483472957520')); @@ -120,5 +120,4 @@ void main() { expect(bc.normalize('001054'), equals('00000514')); //another special case } }); - }