Files
SpotiFLAC-Mobile/lib/services/setup_progress_store.dart
T
zarzet 7628800604 refactor(setup): move SharedPreferences access behind SetupProgressStore and SafMigrationPromptStore
The setup draft and the SAF migration prompt flag were read and written
directly from screens. Keys, JSON shape and defaults are unchanged.
2026-10-19 00:56:52 +07:00

27 lines
820 B
Dart

import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
/// Persists the first-run setup draft so an interrupted setup can resume.
class SetupProgressStore {
SetupProgressStore() : _prefs = SharedPreferences.getInstance();
static const _progressKey = 'setup_progress_v1';
final Future<SharedPreferences> _prefs;
/// The stored draft as raw JSON text, or null when none was saved.
Future<String?> readDraft() async => (await _prefs).getString(_progressKey);
Future<void> writeDraft(Map<String, Object?> draft) async {
final encoded = jsonEncode(draft);
if (!await (await _prefs).setString(_progressKey, encoded)) {
throw StateError('Could not save setup progress');
}
}
Future<void> clear() async {
await (await _prefs).remove(_progressKey);
}
}