BluetoothConnection.init constructor
BluetoothConnection.init()
Implementation
BluetoothConnection.init() {
_bluetoothStateSubscription = FlutterBluePlus.adapterState.listen((state) {
switch (state) {
case BluetoothAdapterState.on:
bluetoothState = BluetoothAdapterState.on;
break;
case BluetoothAdapterState.unauthorized:
bluetoothState = BluetoothAdapterState.unauthorized;
logger.e('Bluetooth is unauthorized');
break;
case BluetoothAdapterState.off:
bluetoothState = BluetoothAdapterState.off;
if (_baseStationConnectionState ==
BaseStationConnectionEnum.connected) {
disconnect();
}
if (Platform.isAndroid) {
try {
FlutterBluePlus.turnOn();
} catch (e) {
logger.e('Failed to turn on Bluetooth');
}
}
break;
default:
break;
}
});
}