Files
pipelines/app/lib/features/settings/settings_topic_store.dart
T

36 lines
994 B
Dart

import 'package:shared_preferences/shared_preferences.dart';
import '../../core/servers/server_scope.dart';
const settingsTopicKey = 'pipelines.next.settingsTopic.v1';
abstract interface class SettingsTopicStore {
Future<String?> load();
Future<void> 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<String?> load() async {
try {
return (await SharedPreferences.getInstance()).getString(key);
} catch (_) {
return null;
}
}
@override
Future<void> save(String topic) async {
try {
await (await SharedPreferences.getInstance()).setString(key, topic);
} catch (_) {
// The mounted category remains usable when local storage is unavailable.
}
}
}