onEvent method
required function listen on dtb_link platform any event change response
Implementation
@override
onEvent(event) {
eventChannel.receiveBroadcastStream().listen((onData) {
_log("dtb_on_data: $onData");
Map<String, dynamic> retData = json.decode(onData);
if (retData["command"] == "system.platform_version") {
systemCtr?.complete(retData["ret"]);
}
if (retData["command"] == "bluetooth.isConnected") {
btCtr?.complete(retData["ret"]);
} else if (retData["command"] == "bluetooth.disconnect") {
btCtr?.complete("${retData["ret"]}");
} else if (retData["command"] == "bluetooth.device_found") {
// btCtr?.complete("${retData["ret"]}");
String? deviceId = retData["ret"]?["device_id"];
String? deviceName = retData["ret"]?["device_name"];
if (deviceId != null && deviceName != null) {
event.call(onData);
}
} else if (retData["command"] == "bluetooth.connect_device") {
int? ret = retData["ret"];
btCtr?.complete(ret);
} else if (retData["command"] == "bluetooth.device_disconnected") {
event.call(onData);
// DemoProvider().deviceDisconnected();
} else if (retData["command"] == "bluetooth.serial_no") {
final success = retData["success"];
if (success == true) {}
final ret = retData["ret"];
// debugPrint("readerId: $readerId");
// var hexRes = hex.decode(readerId.substring(2));
// debugPrint("$hexRes");
// var result = TlvUtils.decode(Uint8List.fromList(hexRes));
// String hexString = hex.encode(result.first.value);d
// debugPrint("result: $hexString");
// List<String> splitted = [];
// for (int i = 0; i < hexString.length; i = i + 2) {
// splitted.add(hexString.substring(i, i + 2));
// }
// String ascii = List.generate(splitted.length, (i) => String.fromCharCode(int.parse(splitted[i], radix: 16))).join();
btCtr?.complete(ret);
} else if (retData["command"] == "dtb_terminal.sync_key_build") {
SyncKeyBuild ret = SyncKeyBuild.fromJson(retData["ret"]);
dtbCtr?.complete(ret);
} else if (retData["command"] == "dtb_terminal.sync_key_parse") {
DownloadKeyRet keys = DownloadKeyRet.fromJson(retData["ret"]["ret"]);
dtbCtr?.complete(keys);
} else if (retData["command"] == "dtb_terminal.echo_build") {
SyncKeyBuild ret = SyncKeyBuild.fromJson(retData["ret"]);
dtbCtr?.complete(ret);
} else if (retData["command"] == "dtb_terminal.echo_parse") {
// DownloadKeyRet keys = DownloadKeyRet.fromJson(retData["ret"]["ret"]);
dtbCtr?.complete(retData["ret"]);
} else if (retData["command"] == "bluetooth.download_file") {
int? ret = retData["ret"];
btCtr?.complete(ret);
} else if (retData["command"] == "bluetooth.download_file.pregress") {
// int? current = retData["ret"]?["current"];
// int? total = retData["ret"]?["total"];
event.call(onData);
// DemoProvider().fileDownloadProgress(current, total);
} else if (retData["command"] == "bluetooth.download_file.stopDownload") {
} else if (retData["command"] == "bluetooth.battery_info") {
btCtr?.complete(retData["ret"]);
} else if (retData["command"] == "bluetooth.device_data") {
DeviceData deviceData = DeviceData.fromJson(retData["ret"]);
btCtr?.complete(deviceData);
} else if (retData["command"] == "bluetooth.card_read") {
btCtr?.complete(retData["ret"]);
} else if (retData["command"] == "dtb_terminal.sale_build") {
dtbCtr?.complete(retData["ret"]);
} else if (retData["command"] == "dtb_terminal.sale_parse") {
dtbCtr?.complete(retData["ret"]);
} else if (retData["command"] == "dtb_terminal.register_build") {
dtbCtr?.complete(retData["ret"]);
} else if (retData["command"] == "dtb_terminal.register_parse") {
dtbCtr?.complete(retData["ret"]);
} else if (retData["command"] == "dtb_terminal.complete_build") {
dtbCtr?.complete(retData["ret"]);
} else if (retData["command"] == "dtb_terminal.complete_parse") {
dtbCtr?.complete(retData["ret"]);
} else if (retData["command"] == "dtb_terminal.do_void_build") {
dtbCtr?.complete(retData["ret"]);
} else if (retData["command"] == "dtb_terminal.do_void_parse") {
dtbCtr?.complete(retData["ret"]);
}
});
}