if you disconnect the bluetooth after connecting to it in the app then you will get…
- User
if you disconnect the bluetooth after connecting to it in the app then you will get thrown back to the camera menu and you can connect again but if you connect it now listen twice for the incomming message so it ssems to either save the old listener or it never disconnect the bluetooth device correctly:
void connectToDevice(BuildContext context, String macAddress) async { if (isConnecting) return;
try { print("Connecting to device…"); isConnecting = true;
codetargetDevice = BluetoothDevice(remoteId: DeviceIdentifier(macAddress)); await targetDevice!.connect(); await handleBluetoothDevice(); print("Happening"); isConnecting = false; Navigator.push( context, MaterialPageRoute( builder: (context) => BluetoothScreen(takePictureScreenState: this), ), );} catch (e) { print("Connection error: $e"); isConnecting = false;
codeif (canPop(context)) { Navigator.pop(context); }}
connectionStateSubscription = targetDevice!.connectionState.listen( (BluetoothConnectionState state) { if (state == BluetoothConnectionState.disconnected && canPop(context)) { Navigator.pop(context); } }, ); }
Future handleBluetoothDevice() async { if (targetDevice == null) return;
codeList<BluetoothService> services = await targetDevice!.discoverServices(subscribeToServicesChanged: false); services.forEach((service) { service.characteristics.forEach((characteristic) { if (characteristic.uuid.toString() == "06d1e5e7-79ad-4a71-8faa-373789f7d93c") { print(service); targetCharacteristic = characteristic; characteristic.setNotifyValue(true); print(characteristic); characteristic.lastValueStream.listen((value) { handleReceivedData(value); print("foundit"); }); print("Found it"); } }); });}
void handleReceivedData(List data) { String dataString = String.fromCharCodes(data); try { String numberString = RegExp(r'[0-9.]+').firstMatch(dataString)!.group(0)!; print("We are now here"); print(numberString); captureAndSendImage(numberString); } catch (e) { } }
- Assistant