getHistory static method
Get all sessions, newest first. Optional filters.
Implementation
static Future<List<SessionRecord>> getHistory({
int? limit,
String? stateId,
}) async {
final box = await _openBox();
final records = box.toMap().entries
.where((e) => e.key is String && !(e.key as String).startsWith('_'))
.map((e) {
try {
return SessionRecord.fromJson(Map<String, dynamic>.from(e.value as Map));
} catch (_) {
return null;
}
})
.whereType<SessionRecord>()
.where((r) => stateId == null || r.stateId == stateId)
.toList()
..sort((a, b) => b.completedAt.compareTo(a.completedAt));
if (limit != null && records.length > limit) {
return records.sublist(0, limit);
}
return records;
}