ソースを参照

Merge remote-tracking branch 'origin/master'

maqiang 7 ヶ月 前
コミット
208e896681

+ 43 - 0
android/app/src/main/java/io/flutter/plugins/BluetoothPlugin.java

@@ -33,6 +33,7 @@ import java.security.Permission;
33 33
 import java.util.ArrayList;
34 34
 import java.util.HashMap;
35 35
 import java.util.List;
36
+import java.util.Map;
36 37
 import java.util.concurrent.ExecutorService;
37 38
 import java.util.concurrent.LinkedBlockingDeque;
38 39
 import java.util.concurrent.ThreadFactory;
@@ -170,10 +171,17 @@ public class BluetoothPlugin implements FlutterPlugin, MethodChannel.MethodCallH
170 171
                 Log.d("ble", "startBluetoothPrint :" + methodCall.arguments);
171 172
                 startBluetoothPrintBitMap(methodCall, result);
172 173
                 break;
174
+            case "startBluetoothPrintText":
175
+                Log.d("ble", "startBluetoothPrintText :" + methodCall.arguments);
176
+                startBluetoothPrintText(methodCall, result);
177
+                break;
173 178
             case "startBluetoothPrintBarCode":
174 179
                 Log.d("ble", "startBluetoothPrintBarCode :" + methodCall.arguments);
175 180
                 startBluetoothPrintBarCode(methodCall, result);
176 181
                 break;
182
+            case "startBluetoothPrintBitMapAndText":
183
+                Log.d("ble", "PrintBitMapAndText :" + methodCall.arguments);
184
+                printBitMapAndText(methodCall, result);
177 185
 
178 186
 
179 187
             case "autoLogin":
@@ -333,6 +341,41 @@ public class BluetoothPlugin implements FlutterPlugin, MethodChannel.MethodCallH
333 341
         }
334 342
     }
335 343
 
344
+    void startBluetoothPrintText(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result) {
345
+
346
+        ArrayList<String> textList = (ArrayList<String>) methodCall.arguments;
347
+
348
+        BluetoothDevice bluetoothDevice = mBluetoothAdapter.getRemoteDevice(itemPosition.getDeviceHardwareAddress());
349
+        if (ActivityCompat.checkSelfPermission(_applicationContext, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
350
+            return;
351
+        }
352
+        BlueDeviceInfo blueDeviceInfo = new BlueDeviceInfo(bluetoothDevice.getName(), bluetoothDevice.getAddress(), itemPosition.getConnectState());
353
+        if(blueDeviceInfo.getDeviceName().contains("BTP")) {
354
+            BTPPrintUtil.printText(textList, result);
355
+        } else {
356
+            PrintUtil.printText(textList, result);
357
+        }
358
+    }
359
+
360
+    void printBitMapAndText(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result) {
361
+
362
+        HashMap map = (HashMap)methodCall.arguments;
363
+        byte[] imageByte = (byte[]) map.get("bytes");
364
+        ArrayList<String> textList = (ArrayList<String>) map.get("textList");
365
+
366
+        Bitmap bitmap = Bytes2Bimap(imageByte);
367
+        BluetoothDevice bluetoothDevice = mBluetoothAdapter.getRemoteDevice(itemPosition.getDeviceHardwareAddress());
368
+        if (ActivityCompat.checkSelfPermission(_applicationContext, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
369
+            return;
370
+        }
371
+        BlueDeviceInfo blueDeviceInfo = new BlueDeviceInfo(bluetoothDevice.getName(), bluetoothDevice.getAddress(), itemPosition.getConnectState());
372
+        if(blueDeviceInfo.getDeviceName().contains("BTP")) {
373
+            BTPPrintUtil.PrintBitMapAndText(bitmap,  blueDeviceInfo.getDeviceName(), textList, result);
374
+        }
375
+
376
+    }
377
+
378
+
336 379
     void startBluetoothPrintBarCode(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result) {
337 380
 
338 381
         byte[] imageByte = (byte[]) methodCall.arguments;

+ 123 - 4
android/app/src/main/java/io/flutter/plugins/utils/BTPPrintUtil.java

@@ -10,6 +10,8 @@ import com.snbc.sdk.LabelPrinter;
10 10
 
11 11
 import java.io.ByteArrayOutputStream;
12 12
 import java.nio.ByteBuffer;
13
+import java.util.ArrayList;
14
+import java.util.List;
13 15
 
14 16
 import io.flutter.plugin.common.MethodChannel;
15 17
 
@@ -73,13 +75,130 @@ public class BTPPrintUtil {
73 75
         result.success(code == 0 ? true : false);
74 76
     }
75 77
 
76
-    public  static void printBarCodeWithText(String barCode, String text, @NonNull MethodChannel.Result result) {
78
+    public  static void printText(ArrayList<String> textList,@NonNull MethodChannel.Result result) {
79
+
80
+        int width = 560;
81
+        int height = 640;
82
+        getInstance().SetLabelSize(width,height);
83
+
84
+        int marginX = 2;
85
+        int marginY = 40;
86
+        //矩形框类型
87
+        int rectangleWidth = width - marginX * 2;
88
+        int rectangleHeight = height - marginY * 2;
89
+        int lineWidth = 1;
90
+
91
+        int lineHeight = rectangleHeight / 6;
92
+
93
+        int titleWidth = rectangleWidth / 2;
94
+
95
+        float fontSize = 3;
96
+        // 设置初始偏移量
97
+        int offsetY = 0;
98
+        int offsetX = 0;
99
+        // 计算绘制线条的 y 坐标
100
+        int secondLineY = marginY + lineHeight * 2 - lineWidth + offsetY;
101
+        int thirdLineY = marginY + lineHeight * 3 - lineWidth + offsetY;
102
+        int fourthLineY = marginY + lineHeight * 4 - lineWidth + offsetY;
103
+        int fiveLineY = marginY + lineHeight * 5 - lineWidth + offsetY;
104
+
105
+        int textAlignHorizontal = 0; // 左对齐
106
+
107
+        labelPrinter.PrintText(marginX * 2 + offsetX, marginY + offsetY, "3", textList.get(0), 0, 7, 0, 0);
108
+        labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, marginY + offsetY, "3", textList.get(1), 0, 7, 0, 0);
109
+
110
+
111
+        labelPrinter.PrintText(marginX * 2 + offsetX, marginY + lineHeight - lineWidth + offsetY, "3", textList.get(2), 0, 7, 0, 0);
112
+
113
+
114
+        labelPrinter.PrintText(marginX * 2 + offsetX, secondLineY, "3", textList.get(3), 0, 7, 0, 0);
115
+
116
+
117
+        labelPrinter.PrintText(marginX * 2 + offsetX, thirdLineY, "3", textList.get(4), 0, 7, 0, 0);
118
+        labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, thirdLineY, "3", textList.get(5), 0, 7, 0, 0);
119
+
120
+
121
+        labelPrinter.PrintText(marginX * 2 + offsetX, fourthLineY, "3", textList.get(6), 0, 7, 0, 0);
122
+        labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, fourthLineY, "3", textList.get(7), 0, 7, 0, 0);
123
+
124
+
125
+        labelPrinter.PrintText(marginX * 2 + offsetX, fiveLineY, "3", textList.get(8), 0, 7, 0, 0);
126
+        labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, fiveLineY, "3", textList.get(9), 0, 7, 0, 0);
127
+
77 128
 
78
-        getInstance().SetLabelSize(560,640);
79
-        labelPrinter.PrintBarcodeQR(80, 20,  0, "SHXM2024007404", 'H', 18, 2);
80
-        labelPrinter.PrintText(100, 500, "8", "SHXM2024007404", 0, 7, 3, 0);
81 129
         int code = getInstance().PrintLabel(1,1);
82 130
         result.success(code == 0 ? true : false);
83 131
     }
84 132
 
133
+    // BTP打印机同时打印图标和标签只能调这个,依次printBitMap再printText会导致偶发printText不走。
134
+    public  static  void PrintBitMapAndText(Bitmap bitmap, String deviceName, ArrayList<String> textList,@NonNull MethodChannel.Result result) {
135
+        int x = 0;
136
+        if(deviceName.contains("BTP-UP321")) {
137
+            x = 0;
138
+        } else if(deviceName.contains("BTP-P398PLUS")) {
139
+            x = 40;
140
+        }
141
+        int bytes = bitmap.getByteCount();
142
+        ByteBuffer buf = ByteBuffer.allocate(bytes);
143
+        bitmap.copyPixelsToBuffer(buf);
144
+        ByteArrayOutputStream LionData=new ByteArrayOutputStream();
145
+        bitmap.compress(Bitmap.CompressFormat.PNG, 100, LionData);
146
+
147
+        getInstance().SetLabelSize(560,640*2);
148
+        int code = getInstance().PrintImageData(x, 0, LionData.toByteArray());
149
+
150
+
151
+        int width = 560;
152
+        int height = 640;
153
+
154
+        int marginX = 2;
155
+        int marginY = 80;
156
+        //矩形框类型
157
+        int rectangleWidth = width - marginX * 2;
158
+        int rectangleHeight = height - marginY * 2;
159
+        int lineWidth = 1;
160
+
161
+        int lineHeight = rectangleHeight / 6;
162
+
163
+        int titleWidth = rectangleWidth / 2;
164
+
165
+        float fontSize = 3;
166
+        // 设置初始偏移量
167
+        int offsetY = 680;
168
+        int offsetX = 0;
169
+        // 计算绘制线条的 y 坐标
170
+        int secondLineY = marginY + lineHeight * 2 - lineWidth + offsetY;
171
+        int thirdLineY = marginY + lineHeight * 3 - lineWidth + offsetY;
172
+        int fourthLineY = marginY + lineHeight * 4 - lineWidth + offsetY;
173
+        int fiveLineY = marginY + lineHeight * 5 - lineWidth + offsetY;
174
+
175
+        int textAlignHorizontal = 0; // 左对齐
176
+
177
+        labelPrinter.PrintText(marginX * 2 + offsetX, marginY + offsetY, "3", textList.get(0), 0, 7, 0, 0);
178
+        labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, marginY + offsetY, "3", textList.get(1), 0, 7, 0, 0);
179
+
180
+
181
+        labelPrinter.PrintText(marginX * 2 + offsetX, marginY + lineHeight - lineWidth + offsetY, "3", textList.get(2), 0, 7, 0, 0);
182
+
183
+
184
+        labelPrinter.PrintText(marginX * 2 + offsetX, secondLineY, "3", textList.get(3), 0, 7, 0, 0);
185
+
186
+
187
+        labelPrinter.PrintText(marginX * 2 + offsetX, thirdLineY, "3", textList.get(4), 0, 7, 0, 0);
188
+        labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, thirdLineY, "3", textList.get(5), 0, 7, 0, 0);
189
+
190
+
191
+        labelPrinter.PrintText(marginX * 2 + offsetX, fourthLineY, "3", textList.get(6), 0, 7, 0, 0);
192
+        labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, fourthLineY, "3", textList.get(7), 0, 7, 0, 0);
193
+
194
+
195
+        labelPrinter.PrintText(marginX * 2 + offsetX, fiveLineY, "3", textList.get(8), 0, 7, 0, 0);
196
+        labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, fiveLineY, "3", textList.get(9), 0, 7, 0, 0);
197
+
198
+
199
+
200
+
201
+        getInstance().PrintLabel(1,1);
202
+        result.success(code == 0 ? true : false);
203
+    }
85 204
 }

+ 192 - 0
android/app/src/main/java/io/flutter/plugins/utils/PrintUtil.java

@@ -297,4 +297,196 @@ public class PrintUtil {
297 297
     }
298 298
 
299 299
 
300
+    public static void printText(ArrayList<String> textList, @NonNull MethodChannel.Result result) {
301
+        // 检查是否连接了打印机
302
+        if (PrintUtil.isConnection() != 0) {
303
+            result.success(false);
304
+            return;
305
+        }
306
+
307
+        // 重置错误和取消打印状态
308
+        //重置错误状态变量
309
+        final boolean[] isError = {false};
310
+        //重置取消打印状态变量
311
+        final boolean[] isCancel = {false};
312
+        // 初始化打印数据
313
+        ArrayList<String> jsonList = new ArrayList<>();
314
+        ArrayList<String> infoList = new ArrayList<>();
315
+
316
+        // 在每次打印任务前初始化生成的打印数据页数
317
+        int generatedPrintDataPageCount = 0;
318
+        // 设置打印的总页数和份数
319
+        int pageCount = 1;
320
+        int quantity = 1;
321
+        int totalQuantity = pageCount * quantity;
322
+        //setTotalQuantityOfPrints已废弃,使用方法含义更明确的setTotalPrintQuantity
323
+        PrintUtil.getInstance().setTotalPrintQuantity(totalQuantity);
324
+        // 打印参数设置
325
+        /*
326
+         * 参数1:打印浓度 ,参数2:纸张类型 参数3:打印模式
327
+         * 打印浓度 B50/B50W/T6/T7/T8 建议设置6或8,Z401/B32建议设置8,B3S/B21/B203/B1建议设置3
328
+         */
329
+        PrintUtil.getInstance().startPrintJob(3, 3, 1, new PrintCallback() {
330
+            @Override
331
+            public void onProgress(int pageIndex, int quantityIndex, HashMap<String, Object> hashMap) {
332
+                // 更新打印进度
333
+                String progressMessage = "打印进度:已打印到第" + pageIndex + "页,第" + quantityIndex + "份";
334
+                Log.d("ble", "测试:" + progressMessage);
335
+
336
+                // 处理打印完成情况
337
+                if (pageIndex == pageCount && quantityIndex == quantity) {
338
+                    Log.d("ble", "测试:onProgress: 结束打印");
339
+                    //endJob,使用方法含义更明确的endPrintJob
340
+                    if (PrintUtil.getInstance().endPrintJob()) {
341
+                        Log.d("ble", "结束打印成功");
342
+                    } else {
343
+                        Log.d("ble", "结束打印失败");
344
+                    }
345
+                    result.success(true);
346
+                }
347
+            }
348
+
349
+
350
+            @Override
351
+            public void onError(int i) {
352
+
353
+            }
354
+
355
+
356
+            @Override
357
+            public void onError(int errorCode, int printState) {
358
+                Log.d("ble", "测试:onError");
359
+                isError[0] = true;
360
+                result.success(false);
361
+            }
362
+
363
+            @Override
364
+            public void onCancelJob(boolean isSuccess) {
365
+                //取消打印成功回调
366
+                isCancel[0] = true;
367
+            }
368
+
369
+            /**
370
+             * SDK缓存空闲回调,可以在此处传入打印数据
371
+             *
372
+             * @param pageIndex 当前回调函数处理下一页的打印索引
373
+             * @param bufferSize 缓存空间的大小
374
+             */
375
+            @Override
376
+            public void onBufferFree(int pageIndex, int bufferSize) {
377
+                // 如果出现错误、已取消打印,或 pageIndex 超过总页数,则返回
378
+                if (isError[0] || isCancel[0] || pageIndex > pageCount) {
379
+                    return;
380
+                }
381
+
382
+                Log.d(TAG, "测试-空闲数据回调-数据生成判断-总页数 " + pageCount + ",已生成页数:" + generatedPrintDataPageCount + ",空闲回调数据长度:" + bufferSize);
383
+                // 生成打印数据
384
+                generatePrintDataIfNeeded(textList, bufferSize, generatedPrintDataPageCount, pageCount, jsonList, infoList, quantity);
385
+            }
386
+        });
387
+    }
388
+
389
+
390
+    /**
391
+     * 根据需要生成打印数据,确保不超过总页数限制。
392
+     *
393
+     * @param bufferSize 当前缓存空间的大小。
394
+     */
395
+    private static void generatePrintDataIfNeeded(ArrayList<String> textList,int bufferSize, int generatedPrintDataPageCount, int pageCount, ArrayList<String> jsonList, ArrayList<String> infoList, int quantity) {
396
+        // 如果已生成的打印数据页数小于总页数,则继续生成
397
+        if (generatedPrintDataPageCount < pageCount) {
398
+            // 计算本次要生成的数据长度,以免超过总页数
399
+            int commitDataLength = Math.min((pageCount - generatedPrintDataPageCount), bufferSize);
400
+            // 生成数据
401
+            generateMultiPagePrintData(textList,generatedPrintDataPageCount, generatedPrintDataPageCount + commitDataLength, jsonList, infoList, quantity);
402
+            // 提交打印数据
403
+            PrintUtil.getInstance().commitData(jsonList.subList(generatedPrintDataPageCount, generatedPrintDataPageCount + commitDataLength), infoList.subList(generatedPrintDataPageCount, generatedPrintDataPageCount + commitDataLength));
404
+            // 更新已生成的打印数据页数
405
+            generatedPrintDataPageCount += commitDataLength;
406
+        }
407
+    }
408
+
409
+    /**
410
+     * 生成多页的打印数据。
411
+     *
412
+     * @param index      起始索引,生成数据的起始页。
413
+     * @param cycleIndex 结束索引,生成数据的结束页。
414
+     */
415
+    private static void generateMultiPagePrintData(ArrayList<String> textList, int index, int cycleIndex, ArrayList<String> jsonList, ArrayList<String> infoList, int quantity) {
416
+
417
+
418
+        while (index < cycleIndex) {
419
+
420
+            // 设置打印参数
421
+            float width = 70;
422
+            float height = 72.5F;
423
+            int orientation = 0;
424
+            float marginX = 2.0F;
425
+            float marginY = 10.0F;
426
+            //矩形框类型
427
+            float rectangleWidth = width - marginX * 2;
428
+            float rectangleHeight = height - marginY * 2;
429
+            float lineWidth = 0.5F;
430
+            //1.圆 2.椭圆 3.矩形 4.圆角矩形
431
+            int graphType = 3;
432
+            float lineHeight = rectangleHeight / 6.0F;
433
+//            float titleWidth = rectangleWidth * 2 / 5.0F;
434
+//            float contentWidth = rectangleWidth * 3 / 5.0F;
435
+
436
+            float titleWidth = rectangleWidth / 2.0F;
437
+            float contentWidth = rectangleWidth / 2.0F;
438
+
439
+            float fontSize = 3.0F;
440
+            // 设置初始偏移量
441
+            float offsetY = 0F;
442
+            float offsetX = 0F;
443
+            // 计算绘制线条的 y 坐标
444
+            float secondLineY = marginY + lineHeight * 2 - lineWidth + offsetY;
445
+            float thirdLineY = marginY + lineHeight * 3 - lineWidth + offsetY;
446
+            float fourthLineY = marginY + lineHeight * 4 - lineWidth + offsetY;
447
+            float fiveLineY = marginY + lineHeight * 5 - lineWidth + offsetY;
448
+            List<String> fonts = new ArrayList<>();
449
+            fonts.add("ZT008.ttf");
450
+            // 设置画布大小
451
+            PrintUtil.getInstance().drawEmptyLabel(width, height, orientation, fonts);
452
+
453
+            int textAlignHorizontal = 0; // 左对齐
454
+            // 绘制小标题
455
+            PrintUtil.getInstance().drawLabelText(marginX * 2.5f + offsetX, marginY + offsetY, titleWidth - marginX * 3, lineHeight, textList.get(0), "宋体", fontSize, 0, textAlignHorizontal, 1, 6, 0, 1, new boolean[]{false, false, false, false});
456
+            PrintUtil.getInstance().drawLabelText(marginX * 2.5f + titleWidth + offsetX, marginY + offsetY, contentWidth - marginX * 3, lineHeight, textList.get(1), "宋体", fontSize, 0, 0, 1, 6, 0, 1, new boolean[]{false, false, false, false});
457
+
458
+
459
+            PrintUtil.getInstance().drawLabelText(marginX * 2.5f + offsetX, marginY + lineHeight - lineWidth + offsetY, rectangleWidth - marginX * 3, lineHeight, textList.get(2), "宋体", fontSize, 0, textAlignHorizontal, 1, 6, 0, 1, new boolean[]{false, false, false, false});
460
+
461
+
462
+            PrintUtil.getInstance().drawLabelText(marginX * 2.5f + offsetX, secondLineY, rectangleWidth - marginX * 3, lineHeight, textList.get(3), "宋体", fontSize, 0, textAlignHorizontal, 1, 6, 0, 1, new boolean[]{false, false, false, false});
463
+
464
+
465
+            PrintUtil.getInstance().drawLabelText(marginX * 2.5f + offsetX, thirdLineY, titleWidth - marginX * 3, lineHeight, textList.get(4), "宋体", fontSize, 0, textAlignHorizontal, 1, 6, 0, 1, new boolean[]{false, false, false, false});
466
+            PrintUtil.getInstance().drawLabelText(marginX * 2.5f + titleWidth + offsetX, thirdLineY, contentWidth - marginX * 3, lineHeight, textList.get(5), "宋体", fontSize, 0, 0, 1, 6, 0, 1, new boolean[]{false, false, false, false});
467
+
468
+
469
+            PrintUtil.getInstance().drawLabelText(marginX * 2.5f + offsetX, fourthLineY, titleWidth - marginX * 3, lineHeight, textList.get(6), "宋体", fontSize, 0, textAlignHorizontal, 1, 6, 0, 1, new boolean[]{false, false, false, false});
470
+            PrintUtil.getInstance().drawLabelText(marginX * 2.5f + titleWidth + offsetX, fourthLineY, contentWidth - marginX * 3, lineHeight, textList.get(7), "宋体", fontSize, 0, 0, 1, 6, 0, 1, new boolean[]{false, false, false, false});
471
+
472
+
473
+            PrintUtil.getInstance().drawLabelText(marginX * 2.5f + offsetX, fiveLineY, titleWidth - marginX * 3, lineHeight, textList.get(8), "宋体", fontSize, 0, textAlignHorizontal, 1, 6, 0, 1, new boolean[]{false, false, false, false});
474
+            PrintUtil.getInstance().drawLabelText(marginX * 2.5f + titleWidth + offsetX, fiveLineY, contentWidth - marginX * 3, lineHeight, textList.get(9), "宋体", fontSize, 0, 0, 1, 6, 0, 1, new boolean[]{false, false, false, false});
475
+
476
+            //生成打印数据
477
+            byte[] jsonByte = PrintUtil.getInstance().generateLabelJson();
478
+
479
+            //转换为jsonStr
480
+            String jsonStr = new String(jsonByte);
481
+
482
+
483
+            jsonList.add(jsonStr);
484
+            //除B32/Z401/T8的printMultiple为11.81,其他的为8
485
+            String jsonInfo = "{  " + "\"printerImageProcessingInfo\": " + "{    " + "\"orientation\":" + orientation + "," + "   \"margin\": [      0,      0,      0,      0    ], " + "   \"printQuantity\": " + quantity + ",  " + "  \"horizontalOffset\": 0,  " + "  \"verticalOffset\": 0,  " + "  \"width\":" + width + "," + "   \"height\":" + height + "," + "\"printMultiple\":" + 8 + "," + "  \"epc\": \"\"  }}";
486
+            infoList.add(jsonInfo);
487
+
488
+            index++;
489
+        }
490
+    }
491
+
300 492
 }

+ 9 - 3
lib/page/print/print_page.dart

@@ -20,9 +20,10 @@ import 'dart:ui' as ui;
20 20
 
21 21
 class PrintPageArgs {
22 22
   /// 二维码数据
23
-  Uint8List? bytes;
23
+  Uint8List bytes;
24
+  List<String> textList;
24 25
 
25
-  PrintPageArgs({this.bytes});
26
+  PrintPageArgs({required this.bytes, required this.textList});
26 27
 
27 28
   @override
28 29
   String toString() {
@@ -98,7 +99,12 @@ class _PrintPageState extends BaseLifecycleState<PrintPage> {
98 99
 
99 100
 
100 101
     MyNavigator.showLoading(msg: '打印中...');
101
-    await PrintService.startBluetoothPrintBitMap(smallUint8List!);
102
+    if(PrintService.connectedDeviceList.last.deviceName.contains("BTP")) {
103
+      await PrintService.startBluetoothPrintBitMapAndText(smallUint8List!, widget.args.textList);
104
+    } else {
105
+      await PrintService.startBluetoothPrintBitMap(smallUint8List!);
106
+      await PrintService.startBluetoothPrintText(widget.args.textList);
107
+    }
102 108
     MyNavigator.dismiss();
103 109
     MyNavigator.showToast('打印成功');
104 110
   }

+ 12 - 1
lib/page/sample_task/reap_sample_detail/reap_sample_basic_detail_page.dart

@@ -7,6 +7,8 @@ import 'package:card_swiper/card_swiper.dart';
7 7
 import 'package:flutter/material.dart';
8 8
 import 'package:image_gallery_saver/image_gallery_saver.dart';
9 9
 import 'package:lszlgl/main.dart';
10
+import 'package:lszlgl/page/print/print_page.dart';
11
+import 'package:lszlgl/service/print_service.dart';
10 12
 import 'package:lszlgl/utils/input_formatter.dart';
11 13
 import 'package:lszlgl/utils/location_utils.dart';
12 14
 import 'package:lszlgl/widget/button.dart';
@@ -15,6 +17,7 @@ import '../../../config/colors.dart';
15 17
 import '../../../model/rsp/dict_rsp.dart';
16 18
 import '../../../model/rsp/sample_task_rsp.dart';
17 19
 import '../../../network/my_api.dart';
20
+import '../../../service/dict_service.dart';
18 21
 import '../../../service/user_service.dart';
19 22
 import '../../../utils/file_utils.dart';
20 23
 import '../../../widget/card_item.dart';
@@ -359,7 +362,7 @@ class _ReapSampleBasicDetailPageState extends BaseLifecycleState<ReapSampleBasic
359 362
             ),
360 363
             Row(
361 364
               children: [
362
-                const Expanded(child: MyButton('打印')),
365
+                Expanded(child: MyButton('打印', onTap: () => printPic(picInfo.name))),
363 366
                 const SizedBox(width: 16),
364 367
                 Expanded(child: MyButton('保存图片', onTap: () => savePic(picInfo.name))),
365 368
               ],
@@ -370,6 +373,14 @@ class _ReapSampleBasicDetailPageState extends BaseLifecycleState<ReapSampleBasic
370 373
     );
371 374
   }
372 375
 
376
+  Future<void> printPic(String? name) async {
377
+
378
+    Uint8List? bytes = await FileUtils.getBitmapFromContext(ewmKey.currentContext);
379
+    List<String> textList = PrintService.getPrintTextListWithSampleTaskItem(data);
380
+    var args = PrintPageArgs(bytes: bytes!, textList: textList);
381
+    await MyRouter.startPrint(args);
382
+  }
383
+
373 384
   void savePic(String? name) async {
374 385
     MyNavigator.showLoading(msg: '保存中...');
375 386
     Uint8List? bytes = await FileUtils.getBitmapFromContext(ewmKey.currentContext);

+ 12 - 7
lib/page/sample_task/reap_sample_detail/reap_sample_org_detail_page.dart

@@ -29,6 +29,8 @@ class _ReapSampleOrgDetailPageState extends BaseLifecycleState<ReapSampleOrgDeta
29 29
   String? zldz;
30 30
   String? aqjg;
31 31
   String? aqdz;
32
+  String? pzjg;
33
+  String? pzdz;
32 34
 
33 35
   /// 校验数据
34 36
   bool verifyData() {
@@ -51,6 +53,9 @@ class _ReapSampleOrgDetailPageState extends BaseLifecycleState<ReapSampleOrgDeta
51 53
         } else if (item.sjbj == 3) {
52 54
           aqjg = item.dwmc;
53 55
           aqdz = item.address;
56
+        } else if (item.sjbj == 2) {
57
+          pzjg = item.dwmc;
58
+          pzdz = item.address;
54 59
         }
55 60
       }
56 61
     }
@@ -66,13 +71,13 @@ class _ReapSampleOrgDetailPageState extends BaseLifecycleState<ReapSampleOrgDeta
66 71
     return Column(
67 72
       children: [
68 73
         CardItemWidget(
69
-          '质量检验机构',
74
+          '质量指标检验机构',
70 75
           rightText: zljg,
71 76
           bottomLine: true,
72 77
         ),
73 78
         CardItemWidget(
74
-          '机构地址',
75
-          rightText: zldz,
79
+          '品质指标检验机构',
80
+          rightText: pzjg,
76 81
           bottomLine: true,
77 82
         ),
78 83
         CardItemWidget(
@@ -80,10 +85,10 @@ class _ReapSampleOrgDetailPageState extends BaseLifecycleState<ReapSampleOrgDeta
80 85
           rightText: aqjg,
81 86
           bottomLine: true,
82 87
         ),
83
-        CardItemWidget(
84
-          '机构地址',
85
-          rightText: aqdz,
86
-        ),
88
+        // CardItemWidget(
89
+        //   '机构地址',
90
+        //   rightText: aqdz,
91
+        // ),
87 92
       ],
88 93
     );
89 94
   }

+ 5 - 3
lib/page/sample_task/reap_sample_detail/reap_sample_task_page.dart

@@ -19,6 +19,7 @@ import 'package:lszlgl/page/signature/signature_page.dart';
19 19
 import '../../../base/base_vm.dart';
20 20
 import '../../../main.dart';
21 21
 import '../../../network/my_api.dart';
22
+import '../../../service/print_service.dart';
22 23
 import '../../../utils/file_utils.dart';
23 24
 import '../../../widget/button.dart';
24 25
 import '../../../widget/page_widget.dart';
@@ -223,10 +224,11 @@ class _ReapSampleTaskPageState extends BaseLifecycleState<ReapSampleTaskPage> wi
223 224
 
224 225
   Future<void> printPic(String? name) async {
225 226
 
227
+    SampleTaskItem? req = pageStatus.value.data;
226 228
     Uint8List? bytes = await FileUtils.getBitmapFromContext(ewmKey.currentContext);
227
-
228
-    var args = PrintPageArgs(bytes: bytes);
229
-    await MyRouter.startPrint(args: args);
229
+    List<String> textList = PrintService.getPrintTextListWithSampleTaskItem(req);
230
+    var args = PrintPageArgs(bytes: bytes!, textList: textList);
231
+    await MyRouter.startPrint(args);
230 232
   }
231 233
 
232 234
   void savePic(String? name) async {

+ 19 - 0
lib/plugin/bluetooth_plugin.dart

@@ -91,6 +91,25 @@ class BluetoothPlugin {
91 91
   }
92 92
 
93 93
   //开始打印
94
+  Future<bool> startBluetoothPrintText(List<String> textList) async {
95
+
96
+    if (Platform.isIOS) {
97
+      return false;
98
+    }
99
+    return _channel.invokeMethod('startBluetoothPrintText', textList).then<bool>((d) => d);
100
+  }
101
+
102
+  //开始打印
103
+  Future<bool> startBluetoothPrintBitMapAndText(Uint8List bytes,List<String> textList) async {
104
+
105
+    if (Platform.isIOS) {
106
+      return false;
107
+    }
108
+    return _channel.invokeMethod('startBluetoothPrintBitMapAndText', {"bytes": bytes, "textList": textList}).then<bool>((d) => d);
109
+  }
110
+
111
+
112
+  //开始打印
94 113
   Future<bool> startBluetoothPrintBarCodeWithText(String barCode, String text) async {
95 114
 
96 115
     if (Platform.isIOS) {

+ 2 - 2
lib/router/my_router.dart

@@ -117,8 +117,8 @@ class MyRouter {
117 117
   }
118 118
 
119 119
   /// 打印任务
120
-  static Future<dynamic> startPrint({PrintPageArgs? args}) {
121
-    return MyNavigator.push(rPrintPage, args: args ?? PrintPageArgs());
120
+  static Future<dynamic> startPrint(PrintPageArgs args) {
121
+    return MyNavigator.push(rPrintPage, args: args);
122 122
   }
123 123
 
124 124
   /// 打印任务

+ 38 - 0
lib/service/print_service.dart

@@ -6,11 +6,14 @@ import 'package:device_info_plus/device_info_plus.dart';
6 6
 import 'package:lszlgl/utils/permission_utils.dart';
7 7
 import 'package:permission_handler/permission_handler.dart';
8 8
 
9
+import '../model/rsp/sample_task_rsp.dart';
9 10
 import '../plugin/bluetooth_plugin.dart';
10 11
 import '../router/my_navigator.dart';
11 12
 import 'package:flutter/material.dart';
12 13
 import 'package:flutter/services.dart';
13 14
 
15
+import 'dict_service.dart';
16
+
14 17
 class PrintService {
15 18
   PrintService._();
16 19
 
@@ -136,6 +139,16 @@ class PrintService {
136 139
     }
137 140
   }
138 141
 
142
+  // 打印打印图片和文字只给BTP设备使用
143
+  static Future<bool> startBluetoothPrintBitMapAndText(Uint8List bytes,List<String> textList) async {
144
+
145
+    if(await canExecAction()) {
146
+      return await BluetoothPlugin.instance.startBluetoothPrintBitMapAndText(bytes, textList);
147
+    } else {
148
+      return false;
149
+    }
150
+  }
151
+
139 152
   //开始打印图片
140 153
   static Future<bool> startBluetoothPrintBitMap(Uint8List bytes) async {
141 154
 
@@ -146,6 +159,18 @@ class PrintService {
146 159
     }
147 160
   }
148 161
 
162
+  //开始打印文字
163
+  static Future<bool> startBluetoothPrintText(List<String> textList) async {
164
+
165
+    //
166
+
167
+    if(await canExecAction()) {
168
+      return await BluetoothPlugin.instance.startBluetoothPrintText(textList);
169
+    } else {
170
+      return false;
171
+    }
172
+  }
173
+
149 174
   //开始打印二维码和文本
150 175
   static Future<bool> startBluetoothPrintBarCodeWithText(String barCode, String text) async {
151 176
 
@@ -156,6 +181,19 @@ class PrintService {
156 181
     }
157 182
   }
158 183
 
184
+  static List<String> getPrintTextListWithSampleTaskItem(SampleTaskItem? data) {
185
+
186
+    List<String> textList = [];
187
+    textList.addAll(["采样品种:${data?.cypzName ?? ''}","种植品种:${data?.jtpzmc ?? ''}"]);
188
+    textList.addAll(["${data?.shengXzqhName ?? ''}${data?.shiXzqhName ?? ''}${data?.quXzqhName ?? ''}${data?.xiangXzqhName ?? ''}${data?.cunXzqhName ?? ''}"]);
189
+    textList.addAll(["扦样人员:${data?.dgryName ?? ''}"]);
190
+    textList.addAll(["收获时间:${data?.shsj ?? ''}","扦样时间:${data?.qysj ?? ''}"]);
191
+    textList.addAll(["扦样数量:${data?.qysl ?? ''}kg","样品层级:${DictService.getLabel(DictType.ypdj, value: data?.ypdj)}"]);
192
+    textList.addAll(["种植面积:${data?.zzmj ?? ''}亩","代表数量:${(data?.qydbsl ?? '').toString()}公斤"]);
193
+
194
+    return textList;
195
+  }
196
+
159 197
 
160 198
 
161 199