chipweinberger / flutter_blue_plus

Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android, iOS, macOS
Other
781 stars 471 forks source link

[Bug] Hot Restart: stream outputs disconnected when device is still connected (since 1.14.8). #534

Closed Eashubh128 closed 1 year ago

Eashubh128 commented 1 year ago

FlutterBluePlus Version

1.14.11

Flutter Version

3.10.4

What OS?

Android

OS Version

10

What happened?

I have a scaffold body wrapped with StreamBuilder , that pops up a dialog when the device disconnects , as soon as i reach that screen the dialog appears , even if i close the dialog another one appears as the stream sends duplicate events , so i have added a flag that allows only one dialog , But here is the catch the dialog appears , but the device is still connected , as i can send the data to the device .

StreamBuilder<BluetoothConnectionState>( stream: deviceController.connectedDevice?.connectionState ?? const Stream.empty(), builder: (context, snapshot) { log("Stream output is ${snapshot.data} "); if (snapshot.data == BluetoothConnectionState.disconnected) { if (!isDialogup) { WidgetsBinding.instance.addPostFrameCallback( (timeStamp) { setState(() { isDialogup = true; }); AwesomeDialog( context: context, title: "Bluetooth Disconnected", dismissOnTouchOutside: false, desc: "Oops , lost bluetooth connection please try and connect again", btnOkOnPress: () { deviceController.clearConnectedDevice(); Navigator.popUntil( context, ModalRoute.withName("/"), ); }, btnOkText: "Take me to home", btnOkColor: AppColor.greenDarkColor) .show(); }, ); } }

Logs

Restarted application in 3,160ms.
[log] Running Main.dart
I/ViewRootImpl@75d8efb[MainActivity]( 6834): Relayout returned: old=(0,0,1440,2960) new=(0,0,1440,2960) req=(1440,2960)0 dur=12 res=0x1 s={true 516486610944} ch=false
D/permissions_handler( 6834): No permissions found in manifest for: []16
[log] userToken is
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: setLogLevel
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: setLogLevel
[log] check prev called
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: getConnectedSystemDevices
I/flutter ( 6834): [FBP] <getConnectedSystemDevices> result: {devices: []}
I/flutter ( 6834): [FBP] <getAdapterState> args: null
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: getAdapterState
I/flutter ( 6834): [FBP] <getAdapterState> args: null
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: getAdapterState
I/flutter ( 6834): [FBP] <getAdapterState> result: {adapter_state: 4}
I/ViewRootImpl@75d8efb[MainActivity]( 6834): Relayout returned: old=(0,0,1440,2960) new=(0,0,1440,2960) req=(1440,2960)0 dur=8 res=0x1 s={true 516486610944} ch=false
I/flutter ( 6834): [FBP] <getAdapterState> result: {adapter_state: 4}
I/ViewRootImpl@75d8efb[MainActivity]( 6834): Relayout returned: old=(0,0,1440,2960) new=(0,0,1440,2960) req=(1440,2960)0 dur=33 res=0x1 s={true 516486610944} ch=false
I/ViewRootImpl@75d8efb[MainActivity]( 6834): MSG_RESIZED: frame=(0,0,1440,2960) ci=(0,84,0,168) vi=(0,84,0,168) or=1
I/ViewRootImpl@75d8efb[MainActivity]( 6834): ViewPostIme pointer 0
I/ViewRootImpl@75d8efb[MainActivity]( 6834): ViewPostIme pointer 1
I/flutter ( 6834): [FBP] <getConnectedSystemDevices> args: null
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: getConnectedSystemDevices
[log] check prev called
I/flutter ( 6834): [FBP] <getConnectedSystemDevices> result: {devices: []}
I/ViewRootImpl@75d8efb[MainActivity]( 6834): ViewPostIme pointer 0
I/ViewRootImpl@75d8efb[MainActivity]( 6834): ViewPostIme pointer 1
I/flutter ( 6834): 1
I/flutter ( 6834): [FBP] <getAdapterState> args: null
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: getAdapterState
I/flutter ( 6834): [FBP] <getAdapterState> result: {adapter_state: 4}
I/flutter ( 6834): [FBP] <startScan> args: {service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb], mac_addresses: [], allow_duplicates: false, android_scan_mode: 2, android_uses_fine_location: false}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: startScan
D/BluetoothAdapter( 6834): STATE_ON
I/chatty  ( 6834): uid=11028(com.lifesparktech.walk) identical 1 line
D/BluetoothAdapter( 6834): STATE_ON
D/BluetoothAdapter( 6834): BLE support array set: 010011
D/BluetoothLeScanner( 6834): Start Scan with callback
D/BluetoothLeScanner( 6834): onScannerRegistered() - status=0 scannerId=15 mScannerId=0
I/flutter ( 6834): [FBP] <startScan> result: null
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -80, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] <connect> args: {remote_id: 30:83:98:D6:CE:1A, auto_connect: 0}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: connect
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -79, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/BluetoothAdapter( 6834): STATE_ON
D/BluetoothGatt( 6834): connect() - device: 30:83:98:D6:CE:1A, auto: false
D/BluetoothAdapter( 6834): isSecureModeEnabled
D/BluetoothGatt( 6834): registerApp()
D/BluetoothGatt( 6834): registerApp() - UUID=9783656c-3814-4a9f-a163-601a4c652b98
I/flutter ( 6834): [FBP] <connect> result: 0
D/BluetoothGatt( 6834): onClientRegistered() - status=0 clientIf=16
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -90, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/BluetoothGatt( 6834): onClientConnectionState() - status=0 clientIf=16 device=30:83:98:D6:CE:1A
D/[FBP-Android]( 6834): [FBP-Android] onConnectionStateChange: status: 0 (SUCCESS) newState: connected
I/flutter ( 6834): [FBP] [[ OnConnectionStateChanged ]] result: {disconnect_reason_code: 0, disconnect_reason_string: SUCCESS, remote_id: 30:83:98:D6:CE:1A, connection_state: 1}
I/flutter ( 6834): [FBP] <discoverServices> args: 30:83:98:D6:CE:1A
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: discoverServices
D/BluetoothGatt( 6834): discoverServices() - device: 30:83:98:D6:CE:1A
I/flutter ( 6834): [FBP] <discoverServices> result: null
D/BluetoothGatt( 6834): onConnectionUpdated() - Device=30:83:98:D6:CE:1A interval=6 latency=0 timeout=500 status=0
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -83, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/BluetoothGatt( 6834): onSearchComplete() = Device=30:83:98:D6:CE:1A Status=0
D/[FBP-Android]( 6834): [FBP-Android] onServicesDiscovered: count: 5 status: 0
I/flutter ( 6834): [FBP] [[ OnDiscoverServicesResult ]] result: {error_string: GATT_SUCCESS, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, services: [{included_services: [], characteristics: [{secondary_service_uuid: null, descriptors: [], service_uuid: 00001800-0000-1000-8000-00805f9b34fb, remote_id: 30:83:98:D6:CE:1A, characteristic_uuid: 00002a00-0000-1000-8000-00805f9b34fb, value: , properties: {broadcast: 0, write_without_response: 0, notify_encryption_required: 0, read: 1, authenticated_signed_writes: 0, extended_properties: 0, indicate: 0, indicate_encryption_required: 0, write: 0, notify: 0}}, {secondary_service_uuid: null, descriptors: [], service_uuid: 00001800-0000-1000-8000-00805f9b34fb, remote_id: 30:83:98:D6:CE:1A, characteristic_uuid: 00002a01-0000-1000-8000-00805f9b34fb, value: , properties: {broadcast: 0, write_without_response: 0, notify_encryption_required: 0, read: 1, authenticated_signed_writes: 0, extended_properties: 0, indicate: 0, indicate_encryption_required: 0, write: 0,
D/BluetoothGatt( 6834): onConnectionUpdated() - Device=30:83:98:D6:CE:1A interval=39 latency=0 timeout=500 status=0
[log] Stream output is null
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] <readCharacteristic> args: {remote_id: 30:83:98:D6:CE:1A, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, secondary_service_uuid: null, characteristic_uuid: 0000aef3-0000-1000-8000-00805f9b34fb}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: readCharacteristic
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -83, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
I/flutter ( 6834): [FBP] <readCharacteristic> result: null
D/[FBP-Android]( 6834): [FBP-Android] onCharacteristicRead: uuid: 0000aef3-0000-1000-8000-00805f9b34fb status: 0
[log] Stream output is BluetoothConnectionState.connected
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnCharacteristicReceived ]] result: {secondary_service_uuid: null, error_string: GATT_SUCCESS, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, characteristic_uuid: 0000aef3-0000-1000-8000-00805f9b34fb, value: 33372e303030303030}
I/flutter ( 6834): [FBP] <readCharacteristic> args: {remote_id: 30:83:98:D6:CE:1A, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, secondary_service_uuid: null, characteristic_uuid: 0000adf3-0000-1000-8000-00805f9b34fb}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: readCharacteristic
D/[FBP-Android]( 6834): [FBP-Android] onCharacteristicRead: uuid: 0000adf3-0000-1000-8000-00805f9b34fb status: 0
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -90, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -80, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
I/flutter ( 6834): [FBP] <readCharacteristic> result: null
I/flutter ( 6834): [FBP] [[ OnCharacteristicReceived ]] result: {secondary_service_uuid: null, error_string: GATT_SUCCESS, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, characteristic_uuid: 0000adf3-0000-1000-8000-00805f9b34fb, value: 36362e3030}
[log] Battery values in range
[log] CLIENT BATTERY PERCENTAGE is 37.000000
I/flutter ( 6834): [FBP] <readCharacteristic> args: {remote_id: 30:83:98:D6:CE:1A, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, secondary_service_uuid: null, characteristic_uuid: 0000adf9-0000-1000-8000-00805f9b34fb}
[log] SERVER BATTERY PERCENTAGE is 66.00
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: readCharacteristic
D/[FBP-Android]( 6834): [FBP-Android] onCharacteristicRead: uuid: 0000adf9-0000-1000-8000-00805f9b34fb status: 0
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] <readCharacteristic> result: null
I/flutter ( 6834): [FBP] [[ OnCharacteristicReceived ]] result: {secondary_service_uuid: null, error_string: GATT_SUCCESS, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, characteristic_uuid: 0000adf9-0000-1000-8000-00805f9b34fb, value: 322e3030}
[log] SERVER Frequency Value is 2.00
I/flutter ( 6834): [FBP] <readCharacteristic> args: {remote_id: 30:83:98:D6:CE:1A, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, secondary_service_uuid: null, characteristic_uuid: 0000adf8-0000-1000-8000-00805f9b34fb}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: readCharacteristic
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -92, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -91, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
I/flutter ( 6834): [FBP] <readCharacteristic> result: null
D/[FBP-Android]( 6834): [FBP-Android] onCharacteristicRead: uuid: 0000adf8-0000-1000-8000-00805f9b34fb status: 0
I/flutter ( 6834): [FBP] [[ OnCharacteristicReceived ]] result: {secondary_service_uuid: null, error_string: GATT_SUCCESS, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, characteristic_uuid: 0000adf8-0000-1000-8000-00805f9b34fb, value: 34}
I/flutter ( 6834): [FBP] <readCharacteristic> args: {remote_id: 30:83:98:D6:CE:1A, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, secondary_service_uuid: null, characteristic_uuid: 0000aef8-0000-1000-8000-00805f9b34fb}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: readCharacteristic
I/flutter ( 6834): [FBP] <readCharacteristic> result: null
D/[FBP-Android]( 6834): [FBP-Android] onCharacteristicRead: uuid: 0000aef8-0000-1000-8000-00805f9b34fb status: 0
I/flutter ( 6834): [FBP] [[ OnCharacteristicReceived ]] result: {secondary_service_uuid: null, error_string: GATT_SUCCESS, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, characteristic_uuid: 0000aef8-0000-1000-8000-00805f9b34fb, value: 34}
[log] SERVER Magnitude Value is 4
[log] Client Magnitude Value is 4
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -83, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -83, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -80, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -80, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -80, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -84, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -90, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -88, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -79, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -81, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -81, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
D/[FBP-Android]( 6834): [FBP-Android] onScanResult
I/flutter ( 6834): [FBP] [[ OnScanResponse ]] result: {result: {rssi: -82, advertisement_data: {connectable: 1, manufacturer_data: {}, tx_power_level: -9, service_data: {}, local_name: b43, service_uuids: [0000acf0-0000-1000-8000-00805f9b34fb]}, device: {remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}}}
I/flutter ( 6834): [FBP] <stopScan> args: null
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: stopScan
D/BluetoothAdapter( 6834): STATE_ON
D/BluetoothAdapter( 6834): STATE_ON
D/BluetoothLeScanner( 6834): Stop Scan with callback
I/flutter ( 6834): [FBP] <stopScan> result: null
I/ViewRootImpl@75d8efb[MainActivity]( 6834): ViewPostIme pointer 0
I/ViewRootImpl@75d8efb[MainActivity]( 6834): ViewPostIme pointer 1
I/flutter ( 6834): [FBP] <getAdapterState> args: null
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: getAdapterState
[log] Stream output is BluetoothConnectionState.connected
I/flutter ( 6834): [FBP] <getAdapterState> result: {adapter_state: 4}
[log] Sendingmode 4;
I/flutter ( 6834): [FBP] <writeCharacteristic> args: {remote_id: 30:83:98:D6:CE:1A, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, secondary_service_uuid: null, characteristic_uuid: 0000abf1-0000-1000-8000-00805f9b34fb, write_type: 0, value: 6d6f646520343b}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: writeCharacteristic
I/flutter ( 6834): [FBP] <writeCharacteristic> result: null
[log] Stream output is BluetoothConnectionState.connected
D/[FBP-Android]( 6834): [FBP-Android] onCharacteristicWrite: uuid: 0000abf1-0000-1000-8000-00805f9b34fb status: 0
I/flutter ( 6834): [FBP] [[ OnCharacteristicWritten ]] result: {secondary_service_uuid: null, error_string: GATT_SUCCESS, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, characteristic_uuid: 0000abf1-0000-1000-8000-00805f9b34fb}
D/Toast   ( 6834): show: focusDisplayId = 0, isFocusInDesktop = false mCustomDisplayId=-1
V/Toast   ( 6834): SHOW: android.widget.Toast$TN@671c68f
V/Toast   ( 6834): HANDLE SHOW: android.widget.Toast$TN@671c68f mView=null mNextView=android.widget.FrameLayout{a8b4d1c V.E...... ......I. 0,0-0,0}
V/Toast   ( 6834): HANDLE HIDE: android.widget.Toast$TN@671c68f mView=null
I/ViewRootImpl@ece3cab[Toast]( 6834): setView = android.widget.FrameLayout@a8b4d1c TM=true MM=false
I/ViewRootImpl@ece3cab[Toast]( 6834): Relayout returned: old=(0,84,1440,2792) new=(466,2549,974,2692) req=(508,143)0 dur=14 res=0x7 s={true 517135257600} ch=true
I/mali_winsys( 6834): new_window_surface() [508x143] return: 0x3000
I/ViewRootImpl@75d8efb[MainActivity]( 6834): ViewPostIme pointer 0
I/ViewRootImpl@75d8efb[MainActivity]( 6834): ViewPostIme pointer 1
I/ViewRootImpl@ece3cab[Toast]( 6834): MSG_RESIZED: frame=(466,2549,974,2692) ci=(0,0,0,0) vi=(0,0,508,143) or=1
I/flutter ( 6834): [FBP] <getAdapterState> args: null
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: getAdapterState
[log] Stream output is BluetoothConnectionState.connected
I/flutter ( 6834): [FBP] <getAdapterState> result: {adapter_state: 4}
I/flutter ( 6834): [FBP] <writeCharacteristic> args: {remote_id: 30:83:98:D6:CE:1A, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, secondary_service_uuid: null, characteristic_uuid: 0000abf1-0000-1000-8000-00805f9b34fb, write_type: 0, value: 6d6f646520343b}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: writeCharacteristic
[log] Sendingmode 4;
I/flutter ( 6834): [FBP] <writeCharacteristic> result: null
[log] Stream output is BluetoothConnectionState.connected
D/[FBP-Android]( 6834): [FBP-Android] onCharacteristicWrite: uuid: 0000abf1-0000-1000-8000-00805f9b34fb status: 0
I/flutter ( 6834): [FBP] [[ OnCharacteristicWritten ]] result: {secondary_service_uuid: null, error_string: GATT_SUCCESS, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, characteristic_uuid: 0000abf1-0000-1000-8000-00805f9b34fb}
D/Toast   ( 6834): show: focusDisplayId = 0, isFocusInDesktop = false mCustomDisplayId=-1
V/Toast   ( 6834): HIDE: android.widget.Toast$TN@671c68f
V/Toast   ( 6834): HANDLE HIDE: android.widget.Toast$TN@671c68f mView=android.widget.FrameLayout{a8b4d1c V.E...... ........ 0,0-508,143}
V/Toast   ( 6834): REMOVE! android.widget.FrameLayout{a8b4d1c V.E...... ........ 0,0-508,143} in android.widget.Toast$TN@671c68f
I/mali_egl( 6834): eglDestroySurface() in
I/mali_winsys( 6834): delete_surface() [508x143] return
I/mali_egl( 6834): eglDestroySurface() out
W/libEGL  ( 6834): EGLNativeWindowType 0x78c1e9ba90 disconnect failed
I/ViewRootImpl@ece3cab[Toast]( 6834): dispatchDetachedFromWindow
D/InputTransport( 6834): Input channel destroyed: '62c200b', fd=112
V/Toast   ( 6834): SHOW: android.widget.Toast$TN@b8e1f08
V/Toast   ( 6834): HANDLE SHOW: android.widget.Toast$TN@b8e1f08 mView=null mNextView=android.widget.FrameLayout{127d6a1 V.E...... ......I. 0,0-0,0}
V/Toast   ( 6834): HANDLE HIDE: android.widget.Toast$TN@b8e1f08 mView=null
I/ViewRootImpl@66a23b4[Toast]( 6834): setView = android.widget.FrameLayout@127d6a1 TM=true MM=false
I/ViewRootImpl@66a23b4[Toast]( 6834): Relayout returned: old=(0,84,1440,2792) new=(466,2549,974,2692) req=(508,143)0 dur=20 res=0x7 s={true 517135257600} ch=true
I/mali_winsys( 6834): new_window_surface() [508x143] return: 0x3000
I/ViewRootImpl@66a23b4[Toast]( 6834): MSG_RESIZED: frame=(466,2549,974,2692) ci=(0,0,0,0) vi=(0,0,508,143) or=1
V/Toast   ( 6834): HIDE: android.widget.Toast$TN@b8e1f08
V/Toast   ( 6834): HANDLE HIDE: android.widget.Toast$TN@b8e1f08 mView=android.widget.FrameLayout{127d6a1 V.E...... ........ 0,0-508,143}
V/Toast   ( 6834): REMOVE! android.widget.FrameLayout{127d6a1 V.E...... ........ 0,0-508,143} in android.widget.Toast$TN@b8e1f08
I/mali_egl( 6834): eglDestroySurface() in
I/mali_winsys( 6834): delete_surface() [508x143] return
I/mali_egl( 6834): eglDestroySurface() out
W/libEGL  ( 6834): EGLNativeWindowType 0x78c1e9ba90 disconnect failed
I/ViewRootImpl@66a23b4[Toast]( 6834): dispatchDetachedFromWindow
D/InputTransport( 6834): Input channel destroyed: '53de2d7', fd=112

This is basically scanning ->connecting->discovering the services->reading characteristics

Now when i restart the application

Restarted application in 2,821ms.
[log] Running Main.dart
I/ViewRootImpl@75d8efb[MainActivity]( 6834): Relayout returned: old=(0,0,1440,2960) new=(0,0,1440,2960) req=(1440,2960)0 dur=8 res=0x1 s={true 516486610944} ch=false
I/ViewRootImpl@75d8efb[MainActivity]( 6834): MSG_RESIZED: frame=(0,0,1440,2960) ci=(0,84,0,168) vi=(0,84,0,0) or=1
D/permissions_handler( 6834): No permissions found in manifest for: []16
[log] userToken is
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: setLogLevel
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: setLogLevel
[log] check prev called
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: getConnectedSystemDevices
I/flutter ( 6834): [FBP] <getConnectedSystemDevices> result: {devices: [{remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}]}
I/flutter ( 6834): [FBP] <connect> args: {remote_id: 30:83:98:D6:CE:1A, auto_connect: 0}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: connect
D/[FBP-Android]( 6834): [FBP-Android] already connected
I/flutter ( 6834): [FBP] <getAdapterState> args: null
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: getAdapterState
I/flutter ( 6834): [FBP] <getAdapterState> args: null
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: getAdapterState
I/flutter ( 6834): [FBP] <connect> result: 1
I/flutter ( 6834): [FBP] <getAdapterState> result: {adapter_state: 4}
I/flutter ( 6834): [FBP] <getAdapterState> result: {adapter_state: 4}
I/flutter ( 6834): [FBP] <discoverServices> args: 30:83:98:D6:CE:1A
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: discoverServices
D/BluetoothGatt( 6834): discoverServices() - device: 30:83:98:D6:CE:1A
D/BluetoothGatt( 6834): onSearchComplete() = Device=30:83:98:D6:CE:1A Status=0
D/[FBP-Android]( 6834): [FBP-Android] onServicesDiscovered: count: 5 status: 0
I/flutter ( 6834): [FBP] <discoverServices> result: null
I/ViewRootImpl@75d8efb[MainActivity]( 6834): Relayout returned: old=(0,0,1440,2960) new=(0,0,1440,2960) req=(1440,2960)0 dur=7 res=0x1 s={true 516486610944} ch=false
I/flutter ( 6834): [FBP] [[ OnDiscoverServicesResult ]] result: {error_string: GATT_SUCCESS, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, services: [{included_services: [], characteristics: [{secondary_service_uuid: null, descriptors: [], service_uuid: 00001800-0000-1000-8000-00805f9b34fb, remote_id: 30:83:98:D6:CE:1A, characteristic_uuid: 00002a00-0000-1000-8000-00805f9b34fb, value: , properties: {broadcast: 0, write_without_response: 0, notify_encryption_required: 0, read: 1, authenticated_signed_writes: 0, extended_properties: 0, indicate: 0, indicate_encryption_required: 0, write: 0, notify: 0}}, {secondary_service_uuid: null, descriptors: [], service_uuid: 00001800-0000-1000-8000-00805f9b34fb, remote_id: 30:83:98:D6:CE:1A, characteristic_uuid: 00002a01-0000-1000-8000-00805f9b34fb, value: , properties: {broadcast: 0, write_without_response: 0, notify_encryption_required: 0, read: 1, authenticated_signed_writes: 0, extended_properties: 0, indicate: 0, indicate_encryption_required: 0, write: 0,
I/ViewRootImpl@75d8efb[MainActivity]( 6834): Relayout returned: old=(0,0,1440,2960) new=(0,0,1440,2960) req=(1440,2960)0 dur=6 res=0x1 s={true 516486610944} ch=false
I/ViewRootImpl@75d8efb[MainActivity]( 6834): MSG_RESIZED: frame=(0,0,1440,2960) ci=(0,84,0,168) vi=(0,84,0,168) or=1
I/ViewRootImpl@75d8efb[MainActivity]( 6834): ViewPostIme pointer 0
I/ViewRootImpl@75d8efb[MainActivity]( 6834): ViewPostIme pointer 1
I/flutter ( 6834): [FBP] <getConnectedSystemDevices> args: null
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: getConnectedSystemDevices
[log] check prev called
I/flutter ( 6834): [FBP] <getConnectedSystemDevices> result: {devices: [{remote_id: 30:83:98:D6:CE:1A, type: 2, local_name: b43}]}
I/flutter ( 6834): [FBP] <connect> args: {remote_id: 30:83:98:D6:CE:1A, auto_connect: 0}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: connect
D/[FBP-Android]( 6834): [FBP-Android] already connected
I/flutter ( 6834): [FBP] <connect> result: 1
I/flutter ( 6834): [FBP] <discoverServices> args: 30:83:98:D6:CE:1A
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: discoverServices
D/BluetoothGatt( 6834): discoverServices() - device: 30:83:98:D6:CE:1A
I/flutter ( 6834): [FBP] <discoverServices> result: null
D/BluetoothGatt( 6834): onSearchComplete() = Device=30:83:98:D6:CE:1A Status=0
D/[FBP-Android]( 6834): [FBP-Android] onServicesDiscovered: count: 5 status: 0
I/flutter ( 6834): [FBP] [[ OnDiscoverServicesResult ]] result: {error_string: GATT_SUCCESS, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, services: [{included_services: [], characteristics: [{secondary_service_uuid: null, descriptors: [], service_uuid: 00001800-0000-1000-8000-00805f9b34fb, remote_id: 30:83:98:D6:CE:1A, characteristic_uuid: 00002a00-0000-1000-8000-00805f9b34fb, value: , properties: {broadcast: 0, write_without_response: 0, notify_encryption_required: 0, read: 1, authenticated_signed_writes: 0, extended_properties: 0, indicate: 0, indicate_encryption_required: 0, write: 0, notify: 0}}, {secondary_service_uuid: null, descriptors: [], service_uuid: 00001800-0000-1000-8000-00805f9b34fb, remote_id: 30:83:98:D6:CE:1A, characteristic_uuid: 00002a01-0000-1000-8000-00805f9b34fb, value: , properties: {broadcast: 0, write_without_response: 0, notify_encryption_required: 0, read: 1, authenticated_signed_writes: 0, extended_properties: 0, indicate: 0, indicate_encryption_required: 0, write: 0,
[log] Stream output is null
I/flutter ( 6834): [FBP] <readCharacteristic> args: {remote_id: 30:83:98:D6:CE:1A, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, secondary_service_uuid: null, characteristic_uuid: 0000aef3-0000-1000-8000-00805f9b34fb}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: readCharacteristic
I/flutter ( 6834): [FBP] <readCharacteristic> result: null
D/[FBP-Android]( 6834): [FBP-Android] onCharacteristicRead: uuid: 0000aef3-0000-1000-8000-00805f9b34fb status: 0
[log] Stream output is BluetoothConnectionState.disconnected
I/flutter ( 6834): [FBP] [[ OnCharacteristicReceived ]] result: {secondary_service_uuid: null, error_string: GATT_SUCCESS, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, characteristic_uuid: 0000aef3-0000-1000-8000-00805f9b34fb, value: 32332e303030303030}
I/flutter ( 6834): [FBP] <readCharacteristic> args: {remote_id: 30:83:98:D6:CE:1A, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, secondary_service_uuid: null, characteristic_uuid: 0000adf3-0000-1000-8000-00805f9b34fb}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: readCharacteristic
I/flutter ( 6834): [FBP] <readCharacteristic> result: null
D/[FBP-Android]( 6834): [FBP-Android] onCharacteristicRead: uuid: 0000adf3-0000-1000-8000-00805f9b34fb status: 0
[log] Stream output is BluetoothConnectionState.disconnected
I/flutter ( 6834): [FBP] [[ OnCharacteristicReceived ]] result: {secondary_service_uuid: null, error_string: GATT_SUCCESS, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, characteristic_uuid: 0000adf3-0000-1000-8000-00805f9b34fb, value: 35392e3030}
[log] Battery values in range
[log] CLIENT BATTERY PERCENTAGE is 23.000000
[log] SERVER BATTERY PERCENTAGE is 59.00
I/flutter ( 6834): [FBP] <readCharacteristic> args: {remote_id: 30:83:98:D6:CE:1A, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, secondary_service_uuid: null, characteristic_uuid: 0000adf9-0000-1000-8000-00805f9b34fb}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: readCharacteristic
I/flutter ( 6834): [FBP] <readCharacteristic> result: null
[log] Stream output is BluetoothConnectionState.disconnected
D/[FBP-Android]( 6834): [FBP-Android] onCharacteristicRead: uuid: 0000adf9-0000-1000-8000-00805f9b34fb status: 0
I/flutter ( 6834): [FBP] [[ OnCharacteristicReceived ]] result: {secondary_service_uuid: null, error_string: GATT_SUCCESS, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, characteristic_uuid: 0000adf9-0000-1000-8000-00805f9b34fb, value: 322e3030}
I/flutter ( 6834): [FBP] <readCharacteristic> args: {remote_id: 30:83:98:D6:CE:1A, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, secondary_service_uuid: null, characteristic_uuid: 0000adf8-0000-1000-8000-00805f9b34fb}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: readCharacteristic
[log] SERVER Frequency Value is 2.00
I/flutter ( 6834): [FBP] <readCharacteristic> result: null
D/[FBP-Android]( 6834): [FBP-Android] onCharacteristicRead: uuid: 0000adf8-0000-1000-8000-00805f9b34fb status: 0
I/flutter ( 6834): [FBP] [[ OnCharacteristicReceived ]] result: {secondary_service_uuid: null, error_string: GATT_SUCCESS, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, characteristic_uuid: 0000adf8-0000-1000-8000-00805f9b34fb, value: 34}
I/flutter ( 6834): [FBP] <readCharacteristic> args: {remote_id: 30:83:98:D6:CE:1A, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, secondary_service_uuid: null, characteristic_uuid: 0000aef8-0000-1000-8000-00805f9b34fb}
D/[FBP-Android]( 6834): [FBP-Android] onMethodCall: readCharacteristic
I/flutter ( 6834): [FBP] <readCharacteristic> result: null
D/[FBP-Android]( 6834): [FBP-Android] onCharacteristicRead: uuid: 0000aef8-0000-1000-8000-00805f9b34fb status: 0
I/flutter ( 6834): [FBP] [[ OnCharacteristicReceived ]] result: {secondary_service_uuid: null, error_string: GATT_SUCCESS, service_uuid: 0000abf0-0000-1000-8000-00805f9b34fb, success: 1, remote_id: 30:83:98:D6:CE:1A, error_code: 0, characteristic_uuid: 0000aef8-0000-1000-8000-00805f9b34fb, value: 34}
[log] SERVER Magnitude Value is 4
[log] Client Magnitude Value is 4

These magnitude and frequency logs are from the ble device .
chipweinberger commented 1 year ago

onConnectionStateChange only appears once in your logs, so it agrees with what you are saying.

There is logic in the connectionState code to get the initialValue, perhaps this is causing your problem. You should try adding logs and seeing if this is causing your issue.

  Stream<BluetoothConnectionState> get connectionState {
    BluetoothConnectionState initialValue = BluetoothConnectionState.disconnected;
    if (FlutterBluePlus._connectionStates[remoteId] != null) {
      initialValue = _bmToBluetoothConnectionState(FlutterBluePlus._connectionStates[remoteId]!.connectionState);
       print("remoteId $remoteId initialValue $initialValue");
    } else {
       print("remoteId $remoteId no initialValue, assuming disconnected");
    }
    return FlutterBluePlus._methodStream.stream
        .where((m) => m.method == "OnConnectionStateChanged")
        .map((m) => m.arguments)
        .map((args) => BmConnectionStateResponse.fromMap(args))
        .where((p) => p.remoteId == remoteId.str)
        .map((p) => _bmToBluetoothConnectionState(p.connectionState))
        .newStreamWithInitialValue(initialValue);
  }

If you see lots of "assuming disconnected", then you should check that the caching logic is being called and caching the value correctly.

    // keep track of connection states
    if (call.method == "OnConnectionStateChanged") {
      BmConnectionStateResponse response = BmConnectionStateResponse.fromMap(call.arguments);
      _connectionStates[DeviceIdentifier(response.remoteId)] = response;
      if (response.connectionState == BmConnectionStateEnum.disconnected) {
        // clear known services, must call discoverServices again
        _knownServices.remove(DeviceIdentifier(response.remoteId));
      }
    }
Eashubh128 commented 1 year ago

I am sorry , but what do i have to do exactly ? you want me to replace this code in my flutterBluePlus library ?

chipweinberger commented 1 year ago

yes. add those logs!

see readme for how to alter FBP code

Eashubh128 commented 1 year ago

I am getting these logs I/flutter (27974): remoteId 30:83:98:D6:CE:1A no initialValue, assuming disconnected I/flutter (27974): remoteId 30:83:98:D6:CE:1A no initialValue, assuming disconnected I/flutter (27974): remoteId 30:83:98:D6:CE:1A no initialValue, assuming disconnected I/flutter (27974): remoteId 30:83:98:D6:CE:1A no initialValue, assuming disconnected I/flutter (27974): connected devices [BluetoothDevice{remoteId: 30:83:98:D6:CE:1A, localName: b43, type: BluetoothDeviceType.le, isDiscoveringServices: false, services: [BluetoothService{remoteId: 30:83:98:D6:CE:1A, serviceUuid: 00001800-0000-1000-8000-00805f9b34fb, isPrimary: true, characteristics: [BluetoothCharacteristic{remoteId: 30:83:98:D6:CE:1A, serviceUuid: 00001800-0000-1000-8000-00805f9b34fb, secondaryServiceUuid: null, characteristicUuid: 00002a00-0000-1000-8000-00805f9b34fb, descriptors: [], properties: CharacteristicProperties{broadcast: false, read: true, writeWithoutResponse: false, write: false, notify: false, indicate: false, authenticatedSignedWrites: false, extendedProperties: false, notifyEncryptionRequired: false, indicateEncryptionRequired: false}, value: []}, BluetoothCharacteristic{remoteId: 30:83:98:D6:CE:1A, serviceUuid: 00001800-0000-1000-8000-00805f9b34fb, secondaryServiceUuid: null, characteristicUuid: 00002a01-0000-1000-8000-00805f9b34fb, descriptors: [], properties: CharacteristicProperties{broadc I/flutter (27974): remoteId 30:83:98:D6:CE:1A no initialValue, assuming disconnected I/flutter (27974): remoteId 30:83:98:D6:CE:1A no initialValue, assuming disconnected I/flutter (27974): remoteId 30:83:98:D6:CE:1A no initialValue, assuming disconnected I/flutter (27974): remoteId 30:83:98:D6:CE:1A no initialValue, assuming disconnected I/flutter (27974): remoteId 30:83:98:D6:CE:1A no initialValue, assuming disconnected I/flutter (27974): remoteId 30:83:98:D6:CE:1A no initialValue, assuming disconnected

When the connected device was printed just before that i restarted the application , and clicked the button , which checks if there are any connected devices , then if there are connected devices i connect to them and then move to the other screen where i can send an recieve data as soon as i reach that screen the stream outputs this , as the screen is wrapped with stream builder

chipweinberger commented 1 year ago

Can you put a breakpoint here and see if it is called?

    // keep track of connection states
    if (call.method == "OnConnectionStateChanged") {
      BmConnectionStateResponse response = BmConnectionStateResponse.fromMap(call.arguments);
      _connectionStates[DeviceIdentifier(response.remoteId)] = response;
      if (response.connectionState == BmConnectionStateEnum.disconnected) {
        // clear known services, must call discoverServices again
        _knownServices.remove(DeviceIdentifier(response.remoteId));
      }
    }

the question: why is initialValue not set?

Eashubh128 commented 1 year ago

Does it have to do with the flow that i have ? If you want i can explain you the flow maybe that could help you point out something

Eashubh128 commented 1 year ago

Where exactly do i add this ?

    // keep track of connection states
    if (call.method == "OnConnectionStateChanged") {
      BmConnectionStateResponse response = BmConnectionStateResponse.fromMap(call.arguments);
      _connectionStates[DeviceIdentifier(response.remoteId)] = response;
      if (response.connectionState == BmConnectionStateEnum.disconnected) {
        // clear known services, must call discoverServices again
        _knownServices.remove(DeviceIdentifier(response.remoteId));
      }
    }
chipweinberger commented 1 year ago

Perhaps do this:

// keep track of connection states
if (call.method == "OnConnectionStateChanged") {
  BmConnectionStateResponse response = BmConnectionStateResponse.fromMap(call.arguments);
  _connectionStates[DeviceIdentifier(response.remoteId)] = response;
  print("updating _connectionStates $response");
  if (response.connectionState == BmConnectionStateEnum.disconnected) {
    // clear known services, must call discoverServices again
    _knownServices.remove(DeviceIdentifier(response.remoteId));
  }
}
Eashubh128 commented 1 year ago

But how where to add this , that i am unable to under stand

chipweinberger commented 1 year ago

But how where to add this , that i am unable to under stand

Add the print statement here: https://github.com/boskokg/flutter_blue_plus/blob/227be87ee0d5e55f20848553f0ea4d89daca86a3/lib/src/flutter_blue_plus.dart#L267

i restarted the application

I think this might be your problem.

When you restart the application, it probably clears FlutterBluePlus. _connectionStates?

Does the problem only happen when you "hot restart"? Does it happen when you do a full quit + relaunch?

Eashubh128 commented 1 year ago

hot restart , ps: if the problem happens in the hotrestart i assume it would also occur in the full quit + relaunch ?

Eashubh128 commented 1 year ago

So when user clicks on the my device button , if the device is connected then i directly take them to the device page , whose body is wrapped with the connection stream , but if the device is not connected then i take them to the scanning or connection page after which they go to the device page

Eashubh128 commented 1 year ago

It used to work fine , recently it broke, i assumed it to be one of my issues but turns out it had something to do with the library .

Eashubh128 commented 1 year ago

And my flutter_blue_plus.dart is

library flutter_blue_plus;

import 'dart:async';
import 'dart:io';

import 'package:flutter/services.dart';

part 'src/bluetooth_characteristic.dart';
part 'src/bluetooth_descriptor.dart';
part 'src/bluetooth_device.dart';
part 'src/bluetooth_msgs.dart';
part 'src/bluetooth_service.dart';
part 'src/bluetooth_utils.dart';
part 'src/flutter_blue_plus.dart';
part 'src/guid.dart';
part 'src/utils.dart';
chipweinberger commented 1 year ago

So the problem is hot restart?

simple solution: do not use hot restart

It used to work fine

yes there were some changes to fix race conditions in 1.14.8

Eashubh128 commented 1 year ago

Let me have a look to that , whether quit + close also has the issue

Eashubh128 commented 1 year ago

Yes its just hot restart , Quit + relaunch does work as intended

chipweinberger commented 1 year ago

hot restart should be fixed in 1.14.20

I now close all connections when the dart vm is restarted

open a new issue if you have more issues.