From 9e13ce02b129cef65bf90b9cbd1b593844c9d655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=AA=E8=84=96=E5=AD=90?= Date: Sat, 25 Nov 2023 13:55:51 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E5=8F=96=E6=B6=88=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/ios/Podfile.lock | 2 +- example/lib/main.dart | 2 +- ios/Classes/JcPrinterPlugin.m | 14 +++++++++++--- lib/jc_printer.dart | 6 +++++- lib/jc_printer_method_channel.dart | 8 +++++++- lib/jc_printer_platform_interface.dart | 11 ++++++++--- 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 35d6dc9..4a44d88 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -35,7 +35,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 integration_test: 13825b8a9334a850581300559b8839134b124670 - jc_printer: c4a2906ddae176e1e82fbf52f337a6b6dfc95f99 + jc_printer: 98d27e989a3129f784669a21dd5883eec26ba102 Protobuf: 351e9022fe13a6e2af00e9aefc22077cb88520f8 reactive_ble_mobile: 9ce6723d37ccf701dbffd202d487f23f5de03b4c SwiftProtobuf: bcfd2bc231cf9ae552cdc7c4e877bd3b41fe57b1 diff --git a/example/lib/main.dart b/example/lib/main.dart index aef9fab..ed34a00 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -106,7 +106,7 @@ class _HomePageState extends State { _count = int.tryParse(_countInput.value.text) ?? 0; final content = _contentInput.value.text.trim(); if (content.isEmpty || _count <= 0) return; - _printer.setTotalPrints(1); + _printer.setTotalPrints(_count); await _printer.initDrawingBoard( width: labelWidth, height: labelHeight, diff --git a/ios/Classes/JcPrinterPlugin.m b/ios/Classes/JcPrinterPlugin.m index 4a1e2aa..3905f95 100644 --- a/ios/Classes/JcPrinterPlugin.m +++ b/ios/Classes/JcPrinterPlugin.m @@ -46,8 +46,10 @@ [self getLabelData:result]; } else if ([@"startJob" isEqualToString:call.method]) { [self startJob:call.arguments result:result]; - } else if ([@"endJob" isEqualToString:call.method]) { - [self endJob:result]; + } else if ([@"cancelJob" isEqualToString:call.method]) { + [self cancelJob:result]; + } else if ([@"endPrint" isEqualToString:call.method]) { + [self endPrint:result]; } else if ([@"commit" isEqualToString:call.method]) { [self commit:call.arguments result:result]; } else { @@ -149,11 +151,17 @@ }]; } -- (void)endJob:(FlutterResult)result { +- (void)endPrint:(FlutterResult)result { [JCAPI endPrint:^(BOOL isSuccess) { result(@(isSuccess)); }]; } + +- (void)cancelJob:(FlutterResult)result { + [JCAPI cancelJob:^(BOOL isSuccess) { + result(@(isSuccess)); + }]; +} #endif #pragma mark - FlutterStreamHandler diff --git a/lib/jc_printer.dart b/lib/jc_printer.dart index 5cbdecd..86f246a 100644 --- a/lib/jc_printer.dart +++ b/lib/jc_printer.dart @@ -227,5 +227,9 @@ class JcPrinter { return _printer.commit(data: data, count: count); } - Future endPrint() async => _printer.endJob(); + /// 取消打印任务 + Future cancelPrint() async => _printer.cancelJob(); + + /// 结束当前打印任务 + Future endPrint() async => _printer.endPrint(); } diff --git a/lib/jc_printer_method_channel.dart b/lib/jc_printer_method_channel.dart index 79bda4d..87a2b6e 100644 --- a/lib/jc_printer_method_channel.dart +++ b/lib/jc_printer_method_channel.dart @@ -153,7 +153,13 @@ class MethodChannelJcPrinter extends JcPrinterPlatform { } @override - Future endJob() async { + Future cancelJob() async { + final result = await method.invokeMethod('cancelJob'); + return result ?? false; + } + + @override + Future endPrint() async { final result = await method.invokeMethod('endJob'); return result ?? false; } diff --git a/lib/jc_printer_platform_interface.dart b/lib/jc_printer_platform_interface.dart index 6441678..180a6a1 100644 --- a/lib/jc_printer_platform_interface.dart +++ b/lib/jc_printer_platform_interface.dart @@ -181,7 +181,7 @@ abstract class JcPrinterPlatform extends PlatformInterface { int rotate = 0, int codeType = 20, int textPosition = 0, -}) { + }) { throw UnimplementedError('drawLabelBarcode() has not been implemented.'); } @@ -202,8 +202,13 @@ abstract class JcPrinterPlatform extends PlatformInterface { throw UnimplementedError('startJob() has not been implemented.'); } - /// 结束打印任务 - Future endJob() async { + /// 取消打印任务 + Future cancelJob() async { + throw UnimplementedError('endJob() has not been implemented.'); + } + + /// 结束当前打印任务 + Future endPrint() async { throw UnimplementedError('endJob() has not been implemented.'); }