Solian/lib/models/notification.dart

60 lines
1.6 KiB
Dart
Raw Normal View History

2024-05-18 10:17:16 +00:00
class Notification {
int id;
DateTime createdAt;
DateTime updatedAt;
DateTime? deletedAt;
String title;
String? subtitle;
String body;
String? avatar;
String? picture;
2024-05-18 10:17:16 +00:00
int? senderId;
int recipientId;
Notification({
required this.id,
required this.createdAt,
required this.updatedAt,
2024-05-28 16:14:41 +00:00
required this.deletedAt,
required this.title,
required this.subtitle,
required this.body,
required this.avatar,
required this.picture,
2024-05-28 16:14:41 +00:00
required this.senderId,
2024-05-18 10:17:16 +00:00
required this.recipientId,
});
factory Notification.fromJson(Map<String, dynamic> json) => Notification(
id: json['id'] ?? 0,
2024-05-28 16:14:41 +00:00
createdAt: json['created_at'] == null
? DateTime.now()
: DateTime.parse(json['created_at']),
updatedAt: json['updated_at'] == null
? DateTime.now()
: DateTime.parse(json['updated_at']),
2024-05-18 10:17:16 +00:00
deletedAt: json['deleted_at'],
title: json['title'],
subtitle: json['subtitle'],
body: json['body'],
avatar: json['avatar'],
picture: json['picture'],
2024-05-18 10:17:16 +00:00
senderId: json['sender_id'],
recipientId: json['recipient_id'],
);
Map<String, dynamic> toJson() => {
'id': id,
'created_at': createdAt.toIso8601String(),
'updated_at': updatedAt.toIso8601String(),
'deleted_at': deletedAt,
'title': title,
'subtitle': subtitle,
'body': body,
'avatar': avatar,
'picture': picture,
2024-05-18 10:17:16 +00:00
'sender_id': senderId,
'recipient_id': recipientId,
};
}