forked from RivaanRanawat/flutter-google-docs-clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument_model.dart
40 lines (35 loc) · 944 Bytes
/
document_model.dart
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
import 'dart:convert';
class DocumentModel {
final String title;
final String uid;
final List content;
final DateTime createdAt;
final String id;
DocumentModel({
required this.title,
required this.uid,
required this.content,
required this.createdAt,
required this.id,
});
Map<String, dynamic> toMap() {
return {
'title': title,
'uid': uid,
'content': content,
'createdAt': createdAt.millisecondsSinceEpoch,
'id': id,
};
}
factory DocumentModel.fromMap(Map<String, dynamic> map) {
return DocumentModel(
title: map['title'] ?? '',
uid: map['uid'] ?? '',
content: List.from(map['content']),
createdAt: DateTime.fromMillisecondsSinceEpoch(map['createdAt']),
id: map['_id'] ?? '',
);
}
String toJson() => json.encode(toMap());
factory DocumentModel.fromJson(String source) => DocumentModel.fromMap(json.decode(source));
}