"This is my code. In the cases of turning Bluetooth on and off, after the 'connect' call, I sequentially receive the 'connecting' state, then the 'disconnected (failure: GenericFailure(code: ConnectionError.failedToConnect, message: "Unknown error"))' state, and finally the 'onDone' state. What is the reason? Am I missing something?"
I/flutter (13530): FINE | BluetoothReactiveDeviceCubit | connect state: connect called
I/flutter (13530): FINE | BluetoothReactiveDeviceCubit | connect state: ConnectionStateUpdate(deviceId: C3:7B:AC:A5:BB:C3, connectionState: DeviceConnectionState.connecting, failure: null)
I/flutter (13530): FINE | BluetoothReactiveDeviceCubit | connect state: ConnectionStateUpdate(deviceId: C3:7B:AC:A5:BB:C3, connectionState: DeviceConnectionState.connecting, failure: null)
I/flutter (13530): FINE | BluetoothReactiveDeviceCubit | connect state: ConnectionStateUpdate(deviceId: C3:7B:AC:A5:BB:C3, connectionState: DeviceConnectionState.disconnected, failure: GenericFailure(code: ConnectionError.failedToConnect, message: "Unknown error"))
I/flutter (13530): FINE | BluetoothReactiveDeviceCubit | connect state done
BluetoothReactiveDeviceCubit({required this.deviceId}) : super(BluetoothReactiveDeviceState.initial(deviceId)) { log.fine('$this Created'); Future.delayed(Duration.zero, () async { _flutterReactiveBle = FlutterReactiveBle(); await _flutterReactiveBle.initialize(); _bluetoothOnOffStream = _flutterReactiveBle.statusStream.listen((status) async { log.fine('bt status: $status'); if (status == BleStatus.poweredOff) { await _blueDeviceStateStream?.cancel(); emit(const BluetoothReactiveDeviceState.disconnected()); } else if (status == BleStatus.ready) { log.fine('connect state: connect called'); await _blueDeviceStateStream?.cancel(); _blueDeviceStateStream = _flutterReactiveBle .connectToDevice( id: deviceId, connectionTimeout: const Duration(seconds: 5), ) .listen((connectionState) async { if (connectionState.connectionState == DeviceConnectionState.connected) { discoverServices(); } else if (connectionState.connectionState == DeviceConnectionState.disconnected) { emit(const BluetoothReactiveDeviceState.disconnected()); } log.fine('connect state: $connectionState'); }, onError: (Object error) { log.warning('connect state error: $error'); emit(const BluetoothReactiveDeviceState.disconnected()); }, onDone: () { log.fine('connect state done'); }); } }); }); }
"This is my code. In the cases of turning Bluetooth on and off, after the 'connect' call, I sequentially receive the 'connecting' state, then the 'disconnected (failure: GenericFailure(code: ConnectionError.failedToConnect, message: "Unknown error"))' state, and finally the 'onDone' state. What is the reason? Am I missing something?"
I/flutter (13530): FINE | BluetoothReactiveDeviceCubit | connect state: connect called I/flutter (13530): FINE | BluetoothReactiveDeviceCubit | connect state: ConnectionStateUpdate(deviceId: C3:7B:AC:A5:BB:C3, connectionState: DeviceConnectionState.connecting, failure: null) I/flutter (13530): FINE | BluetoothReactiveDeviceCubit | connect state: ConnectionStateUpdate(deviceId: C3:7B:AC:A5:BB:C3, connectionState: DeviceConnectionState.connecting, failure: null) I/flutter (13530): FINE | BluetoothReactiveDeviceCubit | connect state: ConnectionStateUpdate(deviceId: C3:7B:AC:A5:BB:C3, connectionState: DeviceConnectionState.disconnected, failure: GenericFailure(code: ConnectionError.failedToConnect, message: "Unknown error"))
I/flutter (13530): FINE | BluetoothReactiveDeviceCubit | connect state done