From aaeba0d02425024ad1d170e7be6afc8f82ae7025 Mon Sep 17 00:00:00 2001 From: Khoren Markosyan Date: Sun, 8 Jan 2023 19:10:37 +0400 Subject: [PATCH] added micro qr code support --- example/lib/main.dart | 37 ++++++++++++++++++++++++------------- lib/src/models/format.dart | 17 ++++++++++++----- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 5cce3da..e808d44 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -69,6 +69,7 @@ class _DemoPageState extends State { else if (result != null) ScanResultWidget( result: result?.text, + format: result?.format?.name, onScanAgain: () => setState(() => result = null), ) else if (result != null) @@ -159,28 +160,38 @@ class ScanResultWidget extends StatelessWidget { const ScanResultWidget({ Key? key, this.result, + this.format, this.onScanAgain, }) : super(key: key); final String? result; + final String? format; final Function()? onScanAgain; @override Widget build(BuildContext context) { return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - result ?? '', - style: Theme.of(context).textTheme.headline6, - ), - const SizedBox(height: 20), - ElevatedButton( - onPressed: onScanAgain, - child: const Text('Scan Again'), - ), - ], + child: Padding( + padding: const EdgeInsets.all(20.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + format ?? '', + style: Theme.of(context).textTheme.headline5, + ), + const SizedBox(height: 20), + Text( + result ?? '', + style: Theme.of(context).textTheme.headline6, + ), + const SizedBox(height: 30), + ElevatedButton( + onPressed: onScanAgain, + child: const Text('Scan Again'), + ), + ], + ), ), ); } diff --git a/lib/src/models/format.dart b/lib/src/models/format.dart index ee948ab..361bda5 100644 --- a/lib/src/models/format.dart +++ b/lib/src/models/format.dart @@ -19,8 +19,9 @@ abstract class Format { static const int qrCode = 1 << 13; // QR Code (2D) static const int upca = 1 << 14; // UPC-A (1D) static const int upce = 1 << 15; // UPC-E (1D) + static const int microQRCode = 1 << 16; // Micro QR Code - static const int oneDCodes = codabar | + static const int linearCodes = codabar | code39 | code93 | code128 | @@ -31,8 +32,9 @@ abstract class Format { dataBarExpanded | upca | upce; - static const int twoDCodes = aztec | dataMatrix | maxiCode | pdf417 | qrCode; - static const int any = oneDCodes | twoDCodes; + static const int matrixCodes = + aztec | dataMatrix | maxiCode | pdf417 | qrCode | microQRCode; + static const int any = linearCodes | matrixCodes; } extension CodeFormat on int { @@ -50,6 +52,7 @@ extension CodeFormat on int { static final List supportedEncodeFormats = [ Format.qrCode, + // Format.microQRCode, Format.dataMatrix, Format.aztec, // Format.pdf417, @@ -86,8 +89,9 @@ final Map barcodeNames = { Format.qrCode: 'QR Code', Format.upca: 'UPCA', Format.upce: 'UPCE', - Format.oneDCodes: 'OneD', - Format.twoDCodes: 'TwoD', + Format.microQRCode: 'Micro QR Code', + Format.linearCodes: 'OneD', + Format.matrixCodes: 'TwoD', Format.any: 'Any', }; @@ -108,6 +112,7 @@ final Map barcodeRatios = { Format.qrCode: 3.0 / 3.0, // recommended ratio: 3:3 (square) Format.upca: 3.0 / 1.0, // recommended ratio: 3:1 Format.upce: 1.0 / 1.0, // recommended ratio: 1:1 (square) + Format.microQRCode: 3.0 / 3.0, // recommended ratio: 3:3 (square) }; final Map barcodeDemoText = { @@ -127,6 +132,7 @@ final Map barcodeDemoText = { Format.qrCode: 'This is a QR Code', Format.upca: '72527273070', Format.upce: '0123456', + Format.microQRCode: 'This is a Micro QR Code', }; final Map barcodeMaxTextLengths = { @@ -146,4 +152,5 @@ final Map barcodeMaxTextLengths = { Format.qrCode: 4296, Format.upca: 12, Format.upce: 8, + Format.microQRCode: 4296, };