initMethodChannel method
void
initMethodChannel(
)
override
Implementation
@override
void initMethodChannel() {
channelStreamController = StreamController<dynamic>.broadcast();
methodChannel.setMethodCallHandler((call) async {
if (call.method == RavenMPosConst.onAlert) {
channelStreamController!.add(RavenMPosEvent(
eventType: RavenMPosEventType.alert,
data: call.arguments['alert']));
logData(call.arguments['alert']);
return;
}
if (call.method == RavenMPosConst.onError) {
channelStreamController!.add(RavenMPosEvent(
eventType: RavenMPosEventType.alert,
data: call.arguments['error']));
return;
}
if (call.method == RavenMPosConst.onBluetoothStartScanning) {
channelStreamController!.add(
RavenMPosEvent(eventType: RavenMPosEventType.scanning, data: true));
return;
}
if (call.method == RavenMPosConst.onBluetoothStopScanning) {
channelStreamController!.add(RavenMPosEvent(
eventType: RavenMPosEventType.stopScanning, data: true));
return;
}
if (call.method == RavenMPosConst.onBluetoothDisconnected) {
bluetoothConnected.value = false;
channelStreamController!.add(RavenMPosEvent(
eventType: RavenMPosEventType.disconnected, data: true));
return;
}
if (call.method == RavenMPosConst.onBluetoothDeviceDetected) {
channelStreamController!.add(RavenMPosEvent(
eventType: RavenMPosEventType.searchedDevices,
data: BluetoothModel.fromJson(jsonDecode(call.arguments))));
return;
}
if (call.method == RavenMPosConst.onBluetoothConnected) {
bluetoothConnected.value = true;
channelStreamController!.add(RavenMPosEvent(
eventType: RavenMPosEventType.connected, data: true));
return;
}
if (call.method == RavenMPosConst.onBluetoothConnectionError) {
bluetoothConnected.value = false;
channelStreamController!.add(RavenMPosEvent(
eventType: RavenMPosEventType.connectionErr, data: null));
return;
}
if (call.method == RavenMPosConst.noDeviceDetectedAnymore) {
bluetoothConnected.value = false;
channelStreamController!.add(RavenMPosEvent(
eventType: RavenMPosEventType.deviceNotDetectedAnymore,
data: null));
return;
}
if (call.method == RavenMPosConst.onFinishedSettingBankBox) {
channelStreamController!.add(RavenMPosEvent(
eventType: RavenMPosEventType.settingCompleted, data: null));
return;
}
if (call.method == RavenMPosConst.onRequestCard) {
channelStreamController!.add(
RavenMPosEvent(eventType: RavenMPosEventType.card, data: null));
return;
}
if (call.method == RavenMPosConst.onRequestPin) {
channelStreamController!
.add(RavenMPosEvent(eventType: RavenMPosEventType.pin, data: null));
return;
}
if (call.method == RavenMPosConst.onPINONPINPAD) {
channelStreamController!.add(
RavenMPosEvent(eventType: RavenMPosEventType.pinPad, data: null));
return;
}
if (call.method == RavenMPosConst.onProcessCardPayment) {
channelStreamController!.add(RavenMPosEvent(
eventType: RavenMPosEventType.processPayment,
data: call.arguments));
return;
}
if (call.method == RavenMPosConst.onTransactionError) {
channelStreamController!.add(RavenMPosEvent(
eventType: RavenMPosEventType.transactionError,
data: call.arguments['error']));
return;
}
if (call.method == RavenMPosConst.onSettingBankBox) {
channelStreamController!.add(RavenMPosEvent(
eventType: RavenMPosEventType.settingBankBox, data: null));
return;
}
if (call.method == RavenMPosConst.onNFCPaymentInitiated) {
channelStreamController!.add(RavenMPosEvent(
eventType: RavenMPosEventType.onNFCPaymentInitiated, data: null));
return;
}
});
}