pending method

Future<List<ReportEvent>> pending()

Returns all pending events in chronological order (by filename/ID).

Implementation

Future<List<ReportEvent>> pending() async {
  final dir = await _ensureDir();
  final entries = await dir.list().toList();
  final files = entries
      .whereType<File>()
      .where((f) => f.path.endsWith('.json'))
      .toList()
    ..sort((a, b) => a.path.compareTo(b.path));

  final result = <ReportEvent>[];
  for (final f in files) {
    try {
      final content = await f.readAsString();
      result.add(ReportEvent.fromJson(content));
    } catch (_) {
      // Corrupt file; delete to avoid blocking the queue.
      try {
        await f.delete();
      } catch (_) {}
    }
  }
  return result;
}