From 88397f858987887dcf7d668c278fc1adeff0a989 Mon Sep 17 00:00:00 2001
From: zhangmeng <494089941@qq.com>
Date: Fri, 15 Oct 2021 13:21:58 +0800
Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 9 +++++++
.../hy/print/hy_printer/HyPrinterPlugin.java | 2 +-
.../com/hy/print/hy_printer/PrintAsOrder.java | 25 ++++++++++---------
example/lib/main.dart | 18 ++++++++++---
lib/hy_printer.dart | 21 ++++++++++++++--
5 files changed, 56 insertions(+), 19 deletions(-)
diff --git a/README.md b/README.md
index 340dff8..6467b89 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,15 @@
汉印打印机插件
仅支持安卓
+###
+在build.gradle中 需要把minSdkVersion 改为19
+权限配置中加入
+```dart
+
+
+
+
+```
##扫描设备
```dart
HyPrinter.getDevices();
diff --git a/android/src/main/java/com/hy/print/hy_printer/HyPrinterPlugin.java b/android/src/main/java/com/hy/print/hy_printer/HyPrinterPlugin.java
index da1defa..bb9a330 100644
--- a/android/src/main/java/com/hy/print/hy_printer/HyPrinterPlugin.java
+++ b/android/src/main/java/com/hy/print/hy_printer/HyPrinterPlugin.java
@@ -56,7 +56,7 @@ public class HyPrinterPlugin implements FlutterPlugin, MethodCallHandler {
}
result.success(status);
} else if (call.method.equals("printAsOrder")) {
- int re = PrintAsOrder.print(call.argument("code"), call.argument("fbaCode"), call.argument("country"), call.argument("channel"), call.argument("count"));
+ int re = PrintAsOrder.print(call.argument("code"), call.argument("fbaCode"), call.argument("country"), call.argument("channel"), call.argument("count"), call.argument("hasPlan"));
result.success(re);
} else if (call.method.equals("printBarCode")) {
int re = -1;
diff --git a/android/src/main/java/com/hy/print/hy_printer/PrintAsOrder.java b/android/src/main/java/com/hy/print/hy_printer/PrintAsOrder.java
index eb4bd36..9e03bae 100644
--- a/android/src/main/java/com/hy/print/hy_printer/PrintAsOrder.java
+++ b/android/src/main/java/com/hy/print/hy_printer/PrintAsOrder.java
@@ -1,7 +1,5 @@
package com.hy.print.hy_printer;
-import android.content.Context;
-
import cpcl.PrinterHelper;
public class PrintAsOrder {
@@ -21,19 +19,18 @@ public class PrintAsOrder {
}
}
- public static int print(String code, String fbaCode, String country, String channel, String count) {
+ public static int print(String code, String fbaCode, String country, String channel, String count, Boolean hasPlan) {
int re = 0;
- if (fbaCode.isEmpty()) {
- re = printNoFba(code, count);
+ if (!hasPlan) {
+ re = printNoPlan(code, count);
} else {
- re = printFba(code, fbaCode, country, channel, count);
+ re = printHasPlan(code, fbaCode, country, channel, count);
}
return re;
}
- ;
- public static int printNoFba(String code, String count) {
+ public static int printNoPlan(String code, String count) {
int reusult = 0;
System.out.println("print start");
try {
@@ -47,14 +44,14 @@ public class PrintAsOrder {
PrinterHelper.Line("42", "228", "550", "228", "2");
setBold();
- PrinterHelper.SetMag("2","2");
+ PrinterHelper.SetMag("2", "2");
PrinterHelper.Text(PrinterHelper.TEXT, "20", "0", "45", "254", "未建计划");
PrinterHelper.Align(PrinterHelper.RIGHT);
PrinterHelper.Text(PrinterHelper.TEXT, "20", "0", "42", "254", "件数");
PrinterHelper.Text(PrinterHelper.TEXT, "20", "0", "42", "300", count);
- PrinterHelper.SetMag("1","1");
+ PrinterHelper.SetMag("1", "1");
closeBold();
PrinterHelper.Align(PrinterHelper.LEFT);
PrinterHelper.Form();
@@ -67,7 +64,7 @@ public class PrintAsOrder {
return reusult;
}
- public static int printFba(String code, String fbaCode, String country, String channel, String count) {
+ public static int printHasPlan(String code, String fbaCode, String country, String channel, String count) {
int reusult = 0;
System.out.println("print start");
try {
@@ -78,7 +75,11 @@ public class PrintAsOrder {
PrinterHelper.SetBold("3");
PrinterHelper.AutCenter(PrinterHelper.TEXT, "45", "170", 500, 4, code);
closeBold();
- fbaCode = "FBA号:" + fbaCode;
+ if (fbaCode.isEmpty()) {
+ fbaCode = "非BFA订单";
+ } else {
+ fbaCode = "FBA号:" + fbaCode;
+ }
PrinterHelper.AutCenter(PrinterHelper.TEXT, "45", "222", 500, 8, fbaCode);
PrinterHelper.Line("42", "269", "550", "269", "2");
setBold();
diff --git a/example/lib/main.dart b/example/lib/main.dart
index 72a72bd..f56c4fe 100644
--- a/example/lib/main.dart
+++ b/example/lib/main.dart
@@ -75,14 +75,24 @@ class _HomeState extends State {
TextButton(
onPressed: () async {
await HyPrinter.printAsOrder(
- 'ASSZ202112120001', '', "", '', "2/10");
+ code: 'ASASNB2021121200010002',
+ fbaCode: '',
+ channel: "",
+ country: '',
+ count: "2/10",
+ hasPlan: false);
setState(() {});
},
- child: const Text('打印非FBA面单')),
+ child: const Text('打印面单')),
TextButton(
onPressed: () async {
- await HyPrinter.printAsOrder('ASSZ202112120001',
- 'FBA15RY33MN8U00001', "欧洲特快", '法国', "2/10");
+ await HyPrinter.printAsOrder(
+ code: 'ASASNB2021121200010002',
+ fbaCode: 'FBA15RY33MN8U00001',
+ channel: "欧洲特快",
+ country: '法国',
+ count: "2/10",
+ hasPlan: true);
setState(() {});
},
child: const Text('打印FBA面单')),
diff --git a/lib/hy_printer.dart b/lib/hy_printer.dart
index 7090561..1b3ade8 100644
--- a/lib/hy_printer.dart
+++ b/lib/hy_printer.dart
@@ -25,6 +25,11 @@ class HyPrinter {
return devices;
}
+ static Future blutIsOn() async {
+ var result = await flutterBlue.isOn;
+ return result;
+ }
+
///0:连接成功
///-1:连接超时
///-2:地址格式错误
@@ -106,14 +111,26 @@ class HyPrinter {
return result;
}
- static Future printAsOrder(String code, String fbaCode, String channel,
- String country, String count) async {
+ /// 'code': code, 箱号
+ // 'fbaCode': fbaCode, fba号/非fba传空字符串
+ // 'channel': channel,渠道名称
+ // 'country': country,目的国
+ // 'count': count,货件数量
+ // 'hasPlan':hasPlan 有无计划
+ static Future printAsOrder(
+ {required String code,
+ required String fbaCode,
+ required String channel,
+ required String country,
+ required String count,
+ required bool hasPlan}) async {
int result = await _channel.invokeMethod('printAsOrder', {
'code': code,
'fbaCode': fbaCode,
'channel': channel,
'country': country,
'count': count,
+ 'hasPlan': hasPlan
});
return result;
}