Browse Source

feat: input zplData

Raihan Rizal 5 months ago
parent
commit
2b5a99fe23

+ 3 - 3
android/src/main/java/id/kalanusa/flutter_zsdk/zplprinthandler/ZplPrintHandler.java

@@ -13,17 +13,17 @@ import io.flutter.plugin.common.MethodChannel;
13 13
 public class ZplPrintHandler {
14 14
 
15 15
     public void handle(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
16
-        printZplOverBluetooth(result);
16
+        printZplOverBluetooth(result, call.argument("zplData"));
17 17
     }
18 18
 
19 19
 
20
-    public void printZplOverBluetooth(@NonNull MethodChannel.Result result) {
20
+    public void printZplOverBluetooth(@NonNull MethodChannel.Result result, String zplData) {
21 21
         new Thread(new Runnable() {
22 22
             @Override
23 23
             public void run() {
24 24
 //                Log.w("From Native (Android)", "isConnected from zplPrinterHandler " + BluetoothConnectionHolder.connection.isConnected() );
25 25
                 try {
26
-                    String zplData = "^XA^PW624^LL800^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^FO20,60^BQ , 60,10 , , , A ^FD 1234ABC.^FS^XZ";
26
+//                    String zplData = "^XA^PW624^LL800^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^FO20,60^BQ , 60,10 , , , A ^FD 1234ABC.^FS^XZ";
27 27
                     BluetoothConnectionHolder.connection.write(zplData.getBytes());
28 28
                 } catch (ConnectionException e) {
29 29
                     Log.w("From Native (Android)", "something went wrong when sending data to printer");

+ 1 - 1
example/lib/main.dart

@@ -154,7 +154,7 @@ class _MyAppState extends State<MyApp> {
154 154
   Future<void> printZplOverBluetooth() async {
155 155
     print('invoked printZplOverBluetooth from dart');
156 156
     try {
157
-      await _flutterZsdkPlugin.printZplOverBluetooth();
157
+      await _flutterZsdkPlugin.printZplOverBluetooth("^XA^PW624^LL800^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^FO20,60^BQ ,2,10 , , , A ^FDQA,http://192.168.102.170:4218/?q=IDC4C321S023^FS^^FO20,320^A0N,25,25^FDDart Zpl Test.^FS^XZ");
158 158
       print('printZplOverBluetooth successfully from dart');
159 159
       
160 160
     } on FlutterZsdkException catch (e) {

+ 2 - 2
lib/flutter_zsdk.dart

@@ -25,7 +25,7 @@ class FlutterZsdk {
25 25
     return FlutterZsdkPlatform.instance.closeConnection();
26 26
   }
27 27
 
28
-  Future<void> printZplOverBluetooth() {
29
-    return FlutterZsdkPlatform.instance.printZplOverBluetooth();
28
+  Future<void> printZplOverBluetooth(String zplData) {
29
+    return FlutterZsdkPlatform.instance.printZplOverBluetooth(zplData);
30 30
   }
31 31
 }

+ 2 - 2
lib/src/flutter_zsdk_method_channel.dart

@@ -115,9 +115,9 @@ class MethodChannelFlutterZsdk extends FlutterZsdkPlatform {
115 115
   }
116 116
 
117 117
   @override
118
-  Future<void> printZplOverBluetooth() async {
118
+  Future<void> printZplOverBluetooth(String zplData) async {
119 119
     try {
120
-      await methodChannel.invokeMethod('printZplOverBluetooth');
120
+      await methodChannel.invokeMethod('printZplOverBluetooth', {'zplData': zplData});
121 121
     } catch (e) {
122 122
       throw FlutterZsdkException("Failed to print ZPL over Bluetooth: $e");
123 123
     }

+ 1 - 1
lib/src/flutter_zsdk_platform_interface.dart

@@ -44,7 +44,7 @@ abstract class FlutterZsdkPlatform extends PlatformInterface {
44 44
     throw UnimplementedError('closeConnection() has not been implemented.');
45 45
   }
46 46
 
47
-  Future<void> printZplOverBluetooth() {
47
+  Future<void> printZplOverBluetooth(String zplData) {
48 48
     throw UnimplementedError('printZplOverBluetooth() has not been implemented.');
49 49
   }
50 50
 }