loadLogs method

Future<List<LogEntry>> loadLogs()

Implementation

Future<List<LogEntry>> loadLogs() async {
  try {
    final file = await _localFile;
    if (!await file.exists()) return [];
    final jsonString = await file.readAsString();
    final jsonLogs = jsonDecode(jsonString) as List;
    return jsonLogs
        .map(
          (json) => LogEntry(
            message: json['message'],
            timestamp: DateTime.parse(json['timestamp']),
            type: json['type'],
          ),
        )
        .toList();
  } catch (e) {
    print('Error loading logs: $e');
    return [];
  }
}