From 5124bcdfcf678e7a35ef5ee133a216bcabe0be61 Mon Sep 17 00:00:00 2001 From: Jonas Greifenhain Date: Tue, 27 May 2025 23:19:50 +0200 Subject: [PATCH] example: Don't disconnect on leaving the details page --- .../peripheral_detail_page.dart | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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) {