|
@@ -3,11 +3,105 @@ Flutter Pluggin for Zebra Multiplatform SDK
|
3
|
3
|
|
4
|
4
|
## Getting Started
|
5
|
5
|
|
6
|
|
-This project is a starting point for a Flutter
|
7
|
|
-[plug-in package](https://flutter.dev/developing-packages/),
|
8
|
|
-a specialized package that includes platform-specific implementation code for
|
9
|
|
-Android and/or iOS.
|
10
|
|
-
|
11
|
|
-For help getting started with Flutter development, view the
|
12
|
|
-[online documentation](https://flutter.dev/docs), which offers tutorials,
|
13
|
|
-samples, guidance on mobile development, and a full API reference.
|
|
6
|
+Add `flutter_zsdk` as a dependency in your `pubspec.yaml` file.
|
|
7
|
+
|
|
8
|
+## Project Setup
|
|
9
|
+
|
|
10
|
+### Android
|
|
11
|
+note: tested using `JDK 17.0.2`, `Gradle 8.0`, `AGP 8.1.3`
|
|
12
|
+
|
|
13
|
+Tambah / ganti `distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip` di android/gradle/wrapper/gradle-wrapper.properties.
|
|
14
|
+
|
|
15
|
+Tambah / ganti `id "com.android.application" version "8.1.3" apply false` di android/settings.gradle.
|
|
16
|
+
|
|
17
|
+Tambah ke file `gradle.properties`.
|
|
18
|
+```
|
|
19
|
+org.gradle.jvmargs=-Xmx4G
|
|
20
|
+android.useAndroidX=true
|
|
21
|
+android.enableJetifier=true
|
|
22
|
+android.jetifier.ignorelist=jackson-core-2.17.2.jar
|
|
23
|
+```
|
|
24
|
+
|
|
25
|
+## Usage
|
|
26
|
+Contoh lengkap bisa dilihat di `example` folder.
|
|
27
|
+
|
|
28
|
+Pertama buat objek dari plugin
|
|
29
|
+```
|
|
30
|
+import 'package:flutter_zsdk/flutter_zsdk.dart';
|
|
31
|
+
|
|
32
|
+final _flutterZsdkPlugin = FlutterZsdk();
|
|
33
|
+
|
|
34
|
+_flutterZsdk.findBluetoothPrinter();
|
|
35
|
+// etc
|
|
36
|
+```
|
|
37
|
+
|
|
38
|
+### Discover Bluetooth Device
|
|
39
|
+Return nilai dari `_flutterZsdkPlugin.findBluetoothPrinter()` itu `Stream<dynamic>` jadi perlu di handle untuk listen ke stream tsb.
|
|
40
|
+
|
|
41
|
+Default event:
|
|
42
|
+- `SOS` : Start of Stream
|
|
43
|
+- `EOS` : End of Stream (`StreamSubscription` harus di cancel jika tidak diperlukan lagi)
|
|
44
|
+
|
|
45
|
+contoh:
|
|
46
|
+```
|
|
47
|
+Future<void> discoverBluetoothDevices() async {
|
|
48
|
+ try {
|
|
49
|
+ Stream<dynamic> stream = await _flutterZsdkPlugin.findBluetoothPrinters();
|
|
50
|
+ _bluetoothPrinterSubscription = stream.listen((event) {
|
|
51
|
+ print(event);
|
|
52
|
+
|
|
53
|
+ if (event == 'SOS') {
|
|
54
|
+ _isDiscovering = true;
|
|
55
|
+
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ if (event is List) {
|
|
59
|
+ // add to list logic here...
|
|
60
|
+
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ if (event == 'EOS') {
|
|
64
|
+ _isDiscovering = false;
|
|
65
|
+ showSnackBar('Bluetooth discovery finished, found ${_discoveredBluetoothPrinters.length} printers');
|
|
66
|
+ _bluetoothPrinterSubscription?.cancel();
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ setState(() {});
|
|
70
|
+ });
|
|
71
|
+
|
|
72
|
+ } on PlatformException catch (e) {
|
|
73
|
+ showSnackBar(e.message.toString());
|
|
74
|
+
|
|
75
|
+ } on FlutterZsdkException catch (e) {
|
|
76
|
+ showSnackBar(e.message);
|
|
77
|
+
|
|
78
|
+ } catch (e) {
|
|
79
|
+ showSnackBar('Unexpected error while discovering bluetooth printers');
|
|
80
|
+
|
|
81
|
+ }
|
|
82
|
+ }
|
|
83
|
+ ```
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+### Connect to Printer
|
|
87
|
+Gunakan `_flutterZsdkPlugin.openConnection(<Mac Address>)`, dimana `<Mac Address>` bisa didapatkan dari `.findBluetoothPrinter()`
|
|
88
|
+
|
|
89
|
+disarankan `.closeConnection()` sebelum melakukan connect ke printer lain. walaupun sudah dihandle disisi plugin.
|
|
90
|
+
|
|
91
|
+### Send ZPL Data to Printer (Print ZPL)
|
|
92
|
+sebelum print, check dulu koneksi ke printer, utk memastikan printer terkoneksi.
|
|
93
|
+
|
|
94
|
+`_flutterZsdkPlugin.isConnected()` utk check koneksi ke printer.
|
|
95
|
+
|
|
96
|
+jika sudah terkoneksi, gunakan `_flutterZsdkPlugin.printZplOverBluetooth(<zpl_data>)` untuk mengirim data ZPL ke printer.
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+### Disconnect from Printer
|
|
100
|
+`_flutterZsdkPlugin.closeConnection()` utk disconnect dari printer.
|
|
101
|
+
|
|
102
|
+</br>
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+note:
|
|
106
|
+- semua aksi harus dipanggil dalam try-catch block
|
|
107
|
+- `_flutterZsdkPlugin.isConnected()` hanya harus dipanggil setelah `_flutterZsdkPlugin.openConnection()` jika tidak app bisa crash (tested ANDROID)
|