loadSettingsSmart static method

Future<MapSettings> loadSettingsSmart()

Smart load: if no local cache, try POD first (for first login). Otherwise load from local cache (fast).

Implementation

static Future<MapSettings> loadSettingsSmart() async {
  try {
    // Check if we have local cache.
    if (await _hasLocalCache()) {
      debugPrint('loadSettingsSmart: using local cache');
      return await _loadFromPrefs();
    }

    // No local cache - only try POD if logged in.

    if (authStateNotifier.value) {
      debugPrint('loadSettingsSmart: no local cache, trying POD...');
      final podData = await readSettingsFromPod();
      if (podData != null) {
        debugPrint('loadSettingsSmart: loaded from POD');
        final settings = _settingsFromJson(podData);

        // Save to local cache.
        await _saveToPrefs(settings);
        return settings;
      }
      debugPrint('loadSettingsSmart: POD empty, using defaults');
    } else {
      debugPrint('loadSettingsSmart: not logged in, using defaults');
    }

    // Use defaults.
    return MapSettings(mapSource: MapSettings.getDefaultMapSource());
  } catch (e) {
    debugPrint('Error in loadSettingsSmart: $e');
    return MapSettings(mapSource: MapSettings.getDefaultMapSource());
  }
}