BleDeviceCubit constructor

BleDeviceCubit()

Implementation

BleDeviceCubit()
    : super(const BleDeviceState(status: BluetoothAdapterState.off)) {
  _adapterStateSubs = FlutterBluePlus.adapterState.listen((state) {
    emit(BleDeviceAuthorizing(status: state));

    if (Platform.isMacOS) {
      return;
    }

    if (state == BluetoothAdapterState.off && Platform.isAndroid) {
      _switchOnBle();
    } else if (state == BluetoothAdapterState.unauthorized) {
      _allowBle();
      // NOTE: on Android, this is necessary, because we get BluetoothAdapterState.on
      //       even when the user denies the permissions
    } else if (state == BluetoothAdapterState.on && Platform.isAndroid) {
      _checkPermissions();
    }
  });
}