模板修改

master
张萌 3 years ago
parent c0db9d2871
commit 88397f8589

@ -2,6 +2,15 @@
汉印打印机插件
仅支持安卓
###
在build.gradle中 需要把minSdkVersion 改为19
权限配置中加入
```dart
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
```
##扫描设备
```dart
HyPrinter.getDevices();

@ -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;

@ -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();

@ -75,14 +75,24 @@ class _HomeState extends State<Home> {
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面单')),

@ -25,6 +25,11 @@ class HyPrinter {
return devices;
}
static Future<bool> blutIsOn() async {
var result = await flutterBlue.isOn;
return result;
}
///0
///-1
///-2
@ -106,14 +111,26 @@ class HyPrinter {
return result;
}
static Future<int> 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<int> 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;
}

Loading…
Cancel
Save