syncFromPod static method
Sync settings from POD to local (background, non-blocking). Call this after login to ensure local settings match POD. Returns the synced settings if POD has data, null otherwise.
Implementation
static Future<MapSettings?> syncFromPod() async {
// CRITICAL: Only sync if logged in.
if (!authStateNotifier.value) {
debugPrint('syncFromPod: skipped (not logged in)');
return null;
}
try {
final podData = await readSettingsFromPod();
if (podData != null) {
debugPrint('syncFromPod: updating local with POD settings');
final settings = _settingsFromJson(podData);
await _saveToPrefs(settings);
return settings;
} else {
// POD has no settings, upload local settings to POD.
debugPrint('syncFromPod: POD empty, uploading local settings');
final localSettings = await _loadFromPrefs();
unawaited(writeSettingsToPod(_settingsToJson(localSettings)));
return null;
}
} catch (e) {
debugPrint('Error syncing from POD: $e');
return null;
}
}