diff --git a/lib/screens/scanner_screen.dart b/lib/screens/scanner_screen.dart index 5d7695c..45fd3fb 100644 --- a/lib/screens/scanner_screen.dart +++ b/lib/screens/scanner_screen.dart @@ -33,9 +33,12 @@ class _ScannerScreenState extends State { _connector = Provider.of(context, listen: false); _connectionListener = () { + final isCurrentRoute = ModalRoute.of(context)?.isCurrent ?? true; if (_connector.state == MeshCoreConnectionState.disconnected) { _changedNavigation = false; } else if (_connector.state == MeshCoreConnectionState.connected && + _connector.activeTransport == MeshCoreTransportType.bluetooth && + isCurrentRoute && !_changedNavigation) { _changedNavigation = true; if (mounted) { diff --git a/lib/services/usb_serial_service_native.dart b/lib/services/usb_serial_service_native.dart index f758a1f..69ed5b8 100644 --- a/lib/services/usb_serial_service_native.dart +++ b/lib/services/usb_serial_service_native.dart @@ -344,10 +344,6 @@ class UsbSerialService { // with a dangling NativeCallable pointer. if (_useDesktopFlSerial) { final serial = _serial; - _serial = null; - _status = UsbSerialStatus.disconnected; - _connectedPortKey = null; - _connectedPortLabel = null; try { if (serial?.isOpen() == FlOpenStatus.open) { serial?.closePort(); // synchronous C call — kills the SerialThread