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
 public class ZplPrintHandler {
13
 public class ZplPrintHandler {
14
 
14
 
15
     public void handle(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
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
         new Thread(new Runnable() {
21
         new Thread(new Runnable() {
22
             @Override
22
             @Override
23
             public void run() {
23
             public void run() {
24
 //                Log.w("From Native (Android)", "isConnected from zplPrinterHandler " + BluetoothConnectionHolder.connection.isConnected() );
24
 //                Log.w("From Native (Android)", "isConnected from zplPrinterHandler " + BluetoothConnectionHolder.connection.isConnected() );
25
                 try {
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
                     BluetoothConnectionHolder.connection.write(zplData.getBytes());
27
                     BluetoothConnectionHolder.connection.write(zplData.getBytes());
28
                 } catch (ConnectionException e) {
28
                 } catch (ConnectionException e) {
29
                     Log.w("From Native (Android)", "something went wrong when sending data to printer");
29
                     Log.w("From Native (Android)", "something went wrong when sending data to printer");

+ 1 - 1
example/lib/main.dart

154
   Future<void> printZplOverBluetooth() async {
154
   Future<void> printZplOverBluetooth() async {
155
     print('invoked printZplOverBluetooth from dart');
155
     print('invoked printZplOverBluetooth from dart');
156
     try {
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
       print('printZplOverBluetooth successfully from dart');
158
       print('printZplOverBluetooth successfully from dart');
159
       
159
       
160
     } on FlutterZsdkException catch (e) {
160
     } on FlutterZsdkException catch (e) {

+ 2 - 2
lib/flutter_zsdk.dart

25
     return FlutterZsdkPlatform.instance.closeConnection();
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
   }
115
   }
116
 
116
 
117
   @override
117
   @override
118
-  Future<void> printZplOverBluetooth() async {
118
+  Future<void> printZplOverBluetooth(String zplData) async {
119
     try {
119
     try {
120
-      await methodChannel.invokeMethod('printZplOverBluetooth');
120
+      await methodChannel.invokeMethod('printZplOverBluetooth', {'zplData': zplData});
121
     } catch (e) {
121
     } catch (e) {
122
       throw FlutterZsdkException("Failed to print ZPL over Bluetooth: $e");
122
       throw FlutterZsdkException("Failed to print ZPL over Bluetooth: $e");
123
     }
123
     }

+ 1 - 1
lib/src/flutter_zsdk_platform_interface.dart

44
     throw UnimplementedError('closeConnection() has not been implemented.');
44
     throw UnimplementedError('closeConnection() has not been implemented.');
45
   }
45
   }
46
 
46
 
47
-  Future<void> printZplOverBluetooth() {
47
+  Future<void> printZplOverBluetooth(String zplData) {
48
     throw UnimplementedError('printZplOverBluetooth() has not been implemented.');
48
     throw UnimplementedError('printZplOverBluetooth() has not been implemented.');
49
   }
49
   }
50
 }
50
 }