42 lines
1.2 KiB
Dart
42 lines
1.2 KiB
Dart
class NotificationModel {
|
|
final String title;
|
|
final String message;
|
|
final bool isRead;
|
|
final String timestamp;
|
|
|
|
NotificationModel({
|
|
required this.title,
|
|
required this.message,
|
|
required this.isRead,
|
|
required this.timestamp,
|
|
});
|
|
|
|
factory NotificationModel.fromMap(Map<dynamic, dynamic> json) {
|
|
return NotificationModel(
|
|
title: json['title'] ?? 'Notifikasi Sistem',
|
|
message: json['message'] ?? '',
|
|
isRead: json['is_read'] ?? json['read'] ?? false,
|
|
timestamp: _parseTimestamp(json['timestamp']),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'title': title,
|
|
'message': message,
|
|
'is_read': isRead,
|
|
'timestamp': timestamp,
|
|
};
|
|
}
|
|
}
|
|
|
|
String _parseTimestamp(dynamic value) {
|
|
if (value == null) return '';
|
|
if (value is int) {
|
|
final dt = DateTime.fromMillisecondsSinceEpoch(value * 1000);
|
|
return "${dt.year}-${dt.month.toString().padLeft(2, '0')}-${dt.day.toString().padLeft(2, '0')} "
|
|
"${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}:${dt.second.toString().padLeft(2, '0')}";
|
|
}
|
|
return value.toString();
|
|
}
|