restore method

Future<AppSnapshot?> restore()

Restore the last saved snapshot.

Returns null if no snapshot exists or if the stored data is corrupt. Corrupt data is automatically wiped.

Implementation

Future<AppSnapshot?> restore() async {
  try {
    final prefs = await SharedPreferences.getInstance();
    final raw = prefs.getString(_snapshotKey);
    if (raw == null) return null;

    final json = jsonDecode(raw);
    if (json is! Map<String, dynamic>) {
      await wipe();
      return null;
    }
    return AppSnapshot.fromJsonSafe(json);
  } catch (_) {
    await wipe();
    return null;
  }
}