import 'package:shared_preferences/shared_preferences.dart'; import '../../core/servers/server_scope.dart'; import '../../core/storage/ordered_local_storage.dart'; const settingsTopicKey = 'pipelines.next.settingsTopic.v1'; abstract interface class SettingsTopicStore { Future load(); Future save(String topic); } /// Stores only the selected category, never unsaved fields or popup state. class SharedPreferencesSettingsTopicStore implements SettingsTopicStore { const SharedPreferencesSettingsTopicStore(this.scope); final String scope; String get key => scopedServerKey(settingsTopicKey, scope); @override Future load() => orderedLocalStorage(key, () async { try { return (await SharedPreferences.getInstance()).getString(key); } catch (_) { return null; } }); @override Future save(String topic) => orderedLocalStorage(key, () async { try { final preferences = await SharedPreferences.getInstance(); await preferences.setString(key, topic); } catch (_) { // The mounted category remains usable when local storage is unavailable. } }); }