Skip to content

Commit e6dd024

Browse files
committed
Added Message Model
1 parent 7b4b26d commit e6dd024

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

mobile/lib/models/message.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class Message {
2+
final String id;
3+
final String senderId;
4+
final String receiverId;
5+
final String content;
6+
final DateTime createdAt;
7+
8+
Message({
9+
required this.id,
10+
required this.senderId,
11+
required this.receiverId,
12+
required this.content,
13+
required this.createdAt,
14+
});
15+
16+
factory Message.fromJson(Map<String, dynamic> json) {
17+
return Message(
18+
id: json['id'],
19+
senderId: json['sender_id'],
20+
receiverId: json['receiver_id'],
21+
content: json['content'],
22+
createdAt: DateTime.parse(json['created_at']),
23+
);
24+
}
25+
26+
factory Message.fromMap(Map<String, dynamic> map) {
27+
return Message(
28+
id: map['id'],
29+
senderId: map['sender_id'],
30+
receiverId: map['receiver_id'],
31+
content: map['content'],
32+
createdAt: DateTime.parse(map['created_at']),
33+
);
34+
}
35+
36+
Map<String, dynamic> toMap() => {
37+
'id': id,
38+
'sender_id': senderId,
39+
'receiver_id': receiverId,
40+
'content': content,
41+
'created_at': createdAt.toIso8601String(),
42+
};
43+
}

0 commit comments

Comments
 (0)