diff --git a/example/lib/peripheral_details/peripheral_detail_page.dart b/example/lib/peripheral_details/peripheral_detail_page.dart index c705848..ed9dcdd 100644 --- a/example/lib/peripheral_details/peripheral_detail_page.dart +++ b/example/lib/peripheral_details/peripheral_detail_page.dart @@ -42,6 +42,19 @@ class _PeripheralDetailPageState extends State { UniversalBle.onConnectionChange = _handleConnectionChange; UniversalBle.onValueChange = _handleValueChange; UniversalBle.onPairingStateChange = _handlePairingStateChange; + _asyncInits(); + } + + void _asyncInits() { + UniversalBle.getConnectionState( + widget.deviceId, + ).then((state) { + if (state == BleConnectionState.connected) { + setState(() { + isConnected = true; + }); + } + }); } @override @@ -49,8 +62,6 @@ class _PeripheralDetailPageState extends State { super.dispose(); UniversalBle.onConnectionChange = null; UniversalBle.onValueChange = null; - // Disconnect when leaving the page - if (isConnected) UniversalBle.disconnect(widget.deviceId); } void _addLog(String type, dynamic data) {