diff --git a/lib/providers/app_provider.dart b/lib/providers/app_provider.dart index 2b2538a..a704fce 100644 --- a/lib/providers/app_provider.dart +++ b/lib/providers/app_provider.dart @@ -39,9 +39,27 @@ class AppProvider with ChangeNotifier { _initializeTileCache(); _initializeLocationTracking(); _loadSimpleMode(); + _syncDrawingsOnStartup(); // Sync drawings immediately after providers load _isInitialized = true; } + /// Sync drawings from messages on app startup (before BLE connection) + Future _syncDrawingsOnStartup() async { + // Wait for MessagesProvider to finish initializing + // DrawingProvider loads around the same time + int attempts = 0; + while (!messagesProvider.isInitialized && attempts < 20) { + await Future.delayed(const Duration(milliseconds: 50)); + attempts++; + } + + // Give DrawingProvider a moment to finish loading too + await Future.delayed(const Duration(milliseconds: 100)); + + debugPrint('🔄 [AppProvider] Early sync: syncing drawings from messages...'); + messagesProvider.syncDrawingsWithProvider(drawingProvider); + } + /// Load simple mode setting from shared preferences Future _loadSimpleMode() async { try {