-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtracked_text.dart
More file actions
41 lines (34 loc) · 1.02 KB
/
Copy pathtracked_text.dart
File metadata and controls
41 lines (34 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import 'package:hive/hive.dart';
part 'tracked_text.g.dart';
/// Domain model representing a tracked text with its timestamp
/// It will also serve as a Hive data model (Adapter will be generated for it)
@HiveType(typeId: 0)
class TrackedText {
@HiveField(0)
final String text;
@HiveField(1)
final List<String> keywords;
@HiveField(2)
final DateTime timestamp;
const TrackedText(this.text, this.keywords, this.timestamp);
}
/// Extension to serialize/deserialize for isolates communication
extension TrackedTextSerialization on TrackedText {
Map<String, dynamic> toMap() {
return {
'text': text,
'keywords': keywords,
'timestamp': timestamp.toIso8601String(),
};
}
static TrackedText fromMap(Map<String, dynamic> map) {
return TrackedText(
map['text'] as String? ?? '',
(map['keywords'] as List<dynamic>?)?.map((e) => e as String).toList() ??
[],
DateTime.parse(
map['timestamp'] as String? ?? DateTime(2000).toIso8601String(),
),
);
}
}