From 917ad90f9d46fcbb2c65e3d4e3f76b59e222a06a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=90=8C?= <494089941@qq.com> Date: Thu, 16 Jun 2022 16:24:36 +0800 Subject: [PATCH] print mode change to black mark from gap(label) --- .idea/libraries/Flutter_Plugins.xml | 1 - .idea/runConfigurations.xml | 10 - .idea/workspace.xml | 28 +-- .../com/dj/printer/dj_printer/AsPrint.java | 2 +- example/lib/main.dart | 4 +- example/pubspec.lock | 68 +++--- lib/dj_printer.dart | 227 +++++++++--------- 7 files changed, 164 insertions(+), 176 deletions(-) delete mode 100644 .idea/runConfigurations.xml diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml index 8b834e2..53449da 100644 --- a/.idea/libraries/Flutter_Plugins.xml +++ b/.idea/libraries/Flutter_Plugins.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 46bd591..3816787 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,9 +5,13 @@ + + + + - - - + + + - - - - - - - - - - + @@ -96,7 +97,6 @@ - diff --git a/android/src/main/java/com/dj/printer/dj_printer/AsPrint.java b/android/src/main/java/com/dj/printer/dj_printer/AsPrint.java index 8b42ea7..eadecff 100644 --- a/android/src/main/java/com/dj/printer/dj_printer/AsPrint.java +++ b/android/src/main/java/com/dj/printer/dj_printer/AsPrint.java @@ -80,7 +80,7 @@ public class AsPrint { channelY = 460;channelX = 220 - channel.length()*10; } cpclPrinter.setForm(0, 203, 203, 800, 575, 0, 1); - cpclPrinter.setMedia(CPCLConst.LK_CPCL_LABEL); + cpclPrinter.setMedia(CPCLConst.LK_CPCL_BLACKMARK); cpclPrinter.setJustification(CPCLConst.LK_CPCL_CENTER); cpclPrinter.printBox(0, 10, 575, 790, 3); cpclPrinter.printLine(0, 160, 570, 160, 3); diff --git a/example/lib/main.dart b/example/lib/main.dart index 21834cf..77e89a3 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -94,6 +94,8 @@ class _MyAppState extends State { ), TextButton( onPressed: () { + int i=0; + while ( i<10){ DjPrinter().printNewAScode( code: 'ASSZ000000002', barCode: 'ASSZ0000000020001', @@ -102,7 +104,7 @@ class _MyAppState extends State { num: '2', sum:'9', offset: 0, - hasPlan: false, ); + hasPlan: true, );i++;} }, child: const Text('打印')), diff --git a/example/pubspec.lock b/example/pubspec.lock index eb956d7..3d9865d 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,70 +5,70 @@ packages: dependency: transitive description: name: async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" barcode: dependency: transitive description: name: barcode - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.2.1" barcode_widget: dependency: "direct main" description: name: barcode_widget - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.0.2" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.0" bot_toast: dependency: "direct main" description: name: bot_toast - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "4.0.2" characters: dependency: transitive description: name: characters - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.2.0" charcode: dependency: transitive description: name: charcode - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.3.1" clock: dependency: transitive description: name: clock - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.0" collection: dependency: transitive description: name: collection - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.16.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.0.5" dj_printer: @@ -82,7 +82,7 @@ packages: dependency: transitive description: name: fake_async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.3.0" flutter: @@ -94,14 +94,14 @@ packages: dependency: transitive description: name: flutter_image_compress - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.0" flutter_lints: dependency: "direct dev" description: name: flutter_lints - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.0.4" flutter_test: @@ -113,84 +113,84 @@ packages: dependency: transitive description: name: lints - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.0.1" matcher: dependency: transitive description: name: matcher - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.12.11" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.1.4" meta: dependency: transitive description: name: meta - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.7.0" path: dependency: transitive description: name: path - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.8.1" permission_handler: dependency: "direct main" description: name: permission_handler - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "9.2.0" permission_handler_android: dependency: transitive description: name: permission_handler_android - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "9.0.2+1" permission_handler_apple: dependency: transitive description: name: permission_handler_apple - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "9.0.4" permission_handler_platform_interface: dependency: transitive description: name: permission_handler_platform_interface - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "3.7.0" permission_handler_windows: dependency: transitive description: name: permission_handler_windows - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.1.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.2" qr: dependency: transitive description: name: qr - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "3.0.1" sky_engine: @@ -202,56 +202,56 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.8.2" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.4.9" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.2" widget_to_image: dependency: "direct main" description: name: widget_to_image - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.0.0" sdks: diff --git a/lib/dj_printer.dart b/lib/dj_printer.dart index 3c1aef0..81f3ca4 100644 --- a/lib/dj_printer.dart +++ b/lib/dj_printer.dart @@ -3,12 +3,9 @@ import 'dart:convert'; import 'dart:typed_data'; import 'dart:ui'; -import 'package:barcode_widget/barcode_widget.dart'; import 'package:dj_printer/src/status_enum.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_image_compress/flutter_image_compress.dart'; -import 'package:widget_to_image/widget_to_image.dart'; class DjPrinter { static late final DjPrinter _instance = DjPrinter._(); @@ -175,109 +172,109 @@ class DjPrinter { required int offset, required bool hasPlan}) async { - - ByteData bDCode = await WidgetToImage.widgetToImage( Directionality( - textDirection: TextDirection.ltr, - child: Material( - child:_getCode(code), - ), - ),pixelRatio: window.devicePixelRatio,size: const Size(25,240)); - - Uint8List uint8ListCode = await testComporessList(bDCode); - - - ByteData bDChannel = await WidgetToImage.widgetToImage( Directionality( - textDirection: TextDirection.ltr, - child: Material( - child:_getChannel(channel) - ), - ),pixelRatio: window.devicePixelRatio,size: const Size(40,140)); - - Uint8List uint8ListChannel = await testComporessList(bDChannel); - - - ByteData bDNum = await WidgetToImage.widgetToImage( Directionality( - textDirection: TextDirection.ltr, - child: Material( - child:_getNum(num) - ), - ),pixelRatio: window.devicePixelRatio,size: Size(20,(20*num.length).toDouble())); - - Uint8List uint8ListNum = await testComporessList(bDNum); - - - ByteData bDSum = await WidgetToImage.widgetToImage( Directionality( - textDirection: TextDirection.ltr, - child: Material( - child:_getNum(sum) - ), - ),pixelRatio: window.devicePixelRatio,size: Size(20,(20*sum.length).toDouble())); - - Uint8List uint8ListSum= await testComporessList(bDSum); - - - Uint8List uint8ListCountry; - if(hasPlan){ - ByteData bDCountry = await WidgetToImage.widgetToImage( Directionality( - textDirection: TextDirection.ltr, - child: Material( - child:_getCountry(country) - ), - ),pixelRatio: window.devicePixelRatio,size: Size(country.length>4?44: 22,70)); - - uint8ListCountry = await testComporessList(bDCountry); - }else{ - ByteData bDCountry = await WidgetToImage.widgetToImage( Directionality( - textDirection: TextDirection.ltr, - child: Material( - child:_getNoplan() - ), - ),pixelRatio: window.devicePixelRatio,size: const Size(22,100)); - - uint8ListCountry = await testComporessList(bDCountry); - } - - - - ByteData bDBarCode = await WidgetToImage.widgetToImage( Directionality( - textDirection: TextDirection.ltr, - child: Material( - child:_getBarCode(code) - ), - ),pixelRatio: window.devicePixelRatio,size: const Size(60,120)); - - Uint8List uint8ListBarCode = await testComporessList(bDBarCode); - - final res = await _channel.invokeMethod('print', { - 'code': code, - 'channel': channel, - 'country': country, - 'countStr': countStr, - 'offset': offset, - 'hasPlan': hasPlan, - 'byteCode': uint8ListCode, - 'bytesChannel':uint8ListChannel, - 'bytesCountry':uint8ListCountry, - 'bytesBarCode':uint8ListBarCode, - 'bytesSum':uint8ListSum, - 'bytesNum':uint8ListNum, - }); - return res; + // + // ByteData bDCode = await WidgetToImage.widgetToImage( Directionality( + // textDirection: TextDirection.ltr, + // child: Material( + // child:_getCode(code), + // ), + // ),pixelRatio: window.devicePixelRatio,size: const Size(25,240)); + // + // Uint8List uint8ListCode = await testComporessList(bDCode); + // + // + // ByteData bDChannel = await WidgetToImage.widgetToImage( Directionality( + // textDirection: TextDirection.ltr, + // child: Material( + // child:_getChannel(channel) + // ), + // ),pixelRatio: window.devicePixelRatio,size: const Size(40,140)); + // + // Uint8List uint8ListChannel = await testComporessList(bDChannel); + // + // + // ByteData bDNum = await WidgetToImage.widgetToImage( Directionality( + // textDirection: TextDirection.ltr, + // child: Material( + // child:_getNum(num) + // ), + // ),pixelRatio: window.devicePixelRatio,size: Size(20,(20*num.length).toDouble())); + // + // Uint8List uint8ListNum = await testComporessList(bDNum); + // + // + // ByteData bDSum = await WidgetToImage.widgetToImage( Directionality( + // textDirection: TextDirection.ltr, + // child: Material( + // child:_getNum(sum) + // ), + // ),pixelRatio: window.devicePixelRatio,size: Size(20,(20*sum.length).toDouble())); + // + // Uint8List uint8ListSum= await testComporessList(bDSum); + // + // + // Uint8List uint8ListCountry; + // if(hasPlan){ + // ByteData bDCountry = await WidgetToImage.widgetToImage( Directionality( + // textDirection: TextDirection.ltr, + // child: Material( + // child:_getCountry(country) + // ), + // ),pixelRatio: window.devicePixelRatio,size: Size(country.length>4?44: 22,70)); + // + // uint8ListCountry = await testComporessList(bDCountry); + // }else{ + // ByteData bDCountry = await WidgetToImage.widgetToImage( Directionality( + // textDirection: TextDirection.ltr, + // child: Material( + // child:_getNoplan() + // ), + // ),pixelRatio: window.devicePixelRatio,size: const Size(22,100)); + // + // uint8ListCountry = await testComporessList(bDCountry); + // } + // + // + // + // ByteData bDBarCode = await WidgetToImage.widgetToImage( Directionality( + // textDirection: TextDirection.ltr, + // child: Material( + // child:_getBarCode(code) + // ), + // ),pixelRatio: window.devicePixelRatio,size: const Size(60,120)); + + // Uint8List uint8ListBarCode = await testComporessList(bDBarCode); + + // final res = await _channel.invokeMethod('print', { + // 'code': code, + // 'channel': channel, + // 'country': country, + // 'countStr': countStr, + // 'offset': offset, + // 'hasPlan': hasPlan, + // 'byteCode': uint8ListCode, + // 'bytesChannel':uint8ListChannel, + // 'bytesCountry':uint8ListCountry, + // 'bytesBarCode':uint8ListBarCode, + // 'bytesSum':uint8ListSum, + // 'bytesNum':uint8ListNum, + // }); + // return res; } - Future testComporessList(ByteData data) async { + // Future testComporessList(ByteData data) async { - final buffer = data.buffer; - - var result = await FlutterImageCompress.compressWithList( - buffer.asUint8List(), - quality: 1, - - ); - print(buffer.asUint8List().length); - print(result.length); - return result; - } + // final buffer = data.buffer; + // + // var result = await FlutterImageCompress.compressWithList( + // buffer.asUint8List(), + // quality: 1, + // + // ); + // print(buffer.asUint8List().length); + // print(result.length); + // return result; + // } Widget _getCountry(String country){ @@ -361,18 +358,18 @@ class DjPrinter { } - Widget _getBarCode(String code){ - return RotatedBox( - quarterTurns: 1, - child: BarcodeWidget( - barcode: Barcode.code128(), - data: code, - style: TextStyle( - fontSize: 10 - ), - ), - ); - } + // Widget _getBarCode(String code){ + // return RotatedBox( + // quarterTurns: 1, + // child: BarcodeWidget( + // barcode: Barcode.code128(), + // data: code, + // style: TextStyle( + // fontSize: 10 + // ), + // ), + // ); + // } Widget _getCard(String code, String channel, String country, String countStr, int offset, bool hasPlan) {