Line data Source code
1 : // Copyright 2026 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'dart:convert';
5 :
6 : import 'package:app_finance/_classes/controller/encryption_handler.dart';
7 :
8 : class LogEntry {
9 : final int index;
10 : final String raw;
11 : bool isExpanded = false;
12 : Map<String, dynamic>? _content;
13 : bool _isParsed = false;
14 :
15 0 : LogEntry(this.index, this.raw);
16 :
17 0 : Map<String, dynamic>? get content {
18 0 : if (!_isParsed) {
19 0 : _isParsed = true;
20 : try {
21 0 : final line = EncryptionHandler.doEncrypt() ? EncryptionHandler.decrypt(raw) : raw;
22 0 : _content = json.decode(line) as Map<String, dynamic>;
23 : } catch (e) {
24 0 : _content = null;
25 : }
26 : }
27 0 : return _content;
28 : }
29 :
30 0 : String get type => content?['type']?['name']?.toString() ?? '?';
31 :
32 0 : DateTime? get date {
33 0 : final data = content?['data'];
34 0 : return DateTime.tryParse(data?['updatedAt'] ?? data?['createdAt'] ?? '');
35 : }
36 :
37 0 : String get formatted => content != null ? const JsonEncoder.withIndent(' ').convert(content) : raw;
38 : }
|