flutter plugin for zebra multiplatform sdk
|
|
4 months ago | |
|---|---|---|
| android | 8 months ago | |
| example | 4 months ago | |
| ios | 8 months ago | |
| lib | 4 months ago | |
| test | 8 months ago | |
| windows | 8 months ago | |
| .gitignore | 8 months ago | |
| .metadata | 1 year ago | |
| CHANGELOG.md | 8 months ago | |
| LICENSE | 8 months ago | |
| README.md | 8 months ago | |
| analysis_options.yaml | 8 months ago | |
| pubspec.yaml | 4 months ago |
Flutter Pluggin for Zebra Multiplatform SDK
Add flutter_zsdk as a dependency in your pubspec.yaml file.
note: tested using JDK 17.0.2, Gradle 8.0, AGP 8.1.3
Tambah / ganti distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip di android/gradle/wrapper/gradle-wrapper.properties.
Tambah / ganti id "com.android.application" version "8.1.3" apply false di android/settings.gradle.
Tambah ke file gradle.properties.
org.gradle.jvmargs=-Xmx4G
android.useAndroidX=true
android.enableJetifier=true
android.jetifier.ignorelist=jackson-core-2.17.2.jar
Contoh lengkap bisa dilihat di example folder.
Pertama buat objek dari plugin
import 'package:flutter_zsdk/flutter_zsdk.dart';
final _flutterZsdkPlugin = FlutterZsdk();
_flutterZsdk.findBluetoothPrinter();
// etc
Return nilai dari _flutterZsdkPlugin.findBluetoothPrinter() itu Stream<dynamic> jadi perlu di handle untuk listen ke stream tsb.
Default event:
SOS : Start of StreamEOS : End of Stream (StreamSubscription harus di cancel jika tidak diperlukan lagi)contoh:
Future<void> discoverBluetoothDevices() async {
try {
Stream<dynamic> stream = await _flutterZsdkPlugin.findBluetoothPrinters();
_bluetoothPrinterSubscription = stream.listen((event) {
print(event);
if (event == 'SOS') {
_isDiscovering = true;
}
if (event is List) {
// add to list logic here...
}
if (event == 'EOS') {
_isDiscovering = false;
showSnackBar('Bluetooth discovery finished, found ${_discoveredBluetoothPrinters.length} printers');
_bluetoothPrinterSubscription?.cancel();
}
setState(() {});
});
} on PlatformException catch (e) {
showSnackBar(e.message.toString());
} on FlutterZsdkException catch (e) {
showSnackBar(e.message);
} catch (e) {
showSnackBar('Unexpected error while discovering bluetooth printers');
}
}
Gunakan _flutterZsdkPlugin.openConnection(<Mac Address>), dimana <Mac Address> bisa didapatkan dari .findBluetoothPrinter()
disarankan .closeConnection() sebelum melakukan connect ke printer lain. walaupun sudah dihandle disisi plugin.
sebelum print, check dulu koneksi ke printer, utk memastikan printer terkoneksi.
_flutterZsdkPlugin.isConnected() utk check koneksi ke printer.
jika sudah terkoneksi, gunakan _flutterZsdkPlugin.printZplOverBluetooth(<zpl_data>) untuk mengirim data ZPL ke printer.
_flutterZsdkPlugin.closeConnection() utk disconnect dari printer.
note:
_flutterZsdkPlugin.isConnected() hanya harus dipanggil setelah _flutterZsdkPlugin.openConnection() jika tidak app bisa crash (tested ANDROID)