class Notification { int id; DateTime createdAt; DateTime updatedAt; DateTime? deletedAt; String subject; String content; List? links; bool isImportant; bool isRealtime; DateTime? readAt; int? senderId; int recipientId; Notification({ required this.id, required this.createdAt, required this.updatedAt, this.deletedAt, required this.subject, required this.content, this.links, required this.isImportant, required this.isRealtime, this.readAt, this.senderId, required this.recipientId, }); factory Notification.fromJson(Map json) => Notification( id: json['id'] ?? 0, createdAt: json['created_at'] == null ? DateTime.now() : DateTime.parse(json['created_at']), updatedAt: json['updated_at'] == null ? DateTime.now() : DateTime.parse(json['updated_at']), deletedAt: json['deleted_at'], subject: json['subject'], content: json['content'], links: json['links'] != null ? List.from(json['links'].map((x) => Link.fromJson(x))) : List.empty(), isImportant: json['is_important'], isRealtime: json['is_realtime'], readAt: json['read_at'], senderId: json['sender_id'], recipientId: json['recipient_id'], ); Map toJson() => { 'id': id, 'created_at': createdAt.toIso8601String(), 'updated_at': updatedAt.toIso8601String(), 'deleted_at': deletedAt, 'subject': subject, 'content': content, 'links': links != null ? List.from(links!.map((x) => x.toJson())) : List.empty(), 'is_important': isImportant, 'is_realtime': isRealtime, 'read_at': readAt, 'sender_id': senderId, 'recipient_id': recipientId, }; } class Link { String label; String url; Link({ required this.label, required this.url, }); factory Link.fromJson(Map json) => Link( label: json['label'], url: json['url'], ); Map toJson() => { 'label': label, 'url': url, }; }