From 42fc1f9cd2f159674cecf94a9b7203a933d705a7 Mon Sep 17 00:00:00 2001 From: Janez T Date: Thu, 5 Mar 2026 20:08:36 +0100 Subject: [PATCH] fix: defer dialog scan start ref: --- lib/widgets/connection_dialog.dart | 16 ++++++++++------ pubspec.lock | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/widgets/connection_dialog.dart b/lib/widgets/connection_dialog.dart index 9e14f5a..f672fb3 100644 --- a/lib/widgets/connection_dialog.dart +++ b/lib/widgets/connection_dialog.dart @@ -47,12 +47,16 @@ class _ConnectionDialogState extends State super.initState(); _tabController = TabController(length: 2, vsync: this); - // Start BLE scan by default - final connectionProvider = Provider.of( - context, - listen: false, - ); - connectionProvider.startScan(); + // Defer scan startup until after the first frame so Provider listeners + // are not notified while this dialog is still being built. + WidgetsBinding.instance.addPostFrameCallback((_) { + if (!mounted) return; + final connectionProvider = Provider.of( + context, + listen: false, + ); + connectionProvider.startScan(); + }); // Set up network scanner callbacks _networkScanner.onServerDiscovered = (server) { diff --git a/pubspec.lock b/pubspec.lock index 71d1c5c..816d214 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -883,7 +883,7 @@ packages: description: path: "." ref: main - resolved-ref: "1617d41ce6e23e00bfad497dbd42259a21302689" + resolved-ref: "47baadb13d5b1b92d1837042ff6b8a39b685295b" url: "https://github.com/dz0ny/meshcore_client.git" source: git version: "0.1.0"