feat: Sync drawings on app startup after provider initialization

This commit is contained in:
Janez T
2025-10-23 20:52:43 +02:00
parent 9d923f8118
commit f15bad5715

View File

@@ -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<void> _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<void> _loadSimpleMode() async {
try {