Initial commit
This commit is contained in:
85
lib/models/event.dart
Normal file
85
lib/models/event.dart
Normal file
@@ -0,0 +1,85 @@
|
||||
class EventItem {
|
||||
final String id;
|
||||
final String entityName;
|
||||
final String description;
|
||||
final List<String> images;
|
||||
final DateTime publishTime;
|
||||
final DateTime? effectiveTime;
|
||||
final DateTime? endTime;
|
||||
final bool popupReminder;
|
||||
final String status;
|
||||
final String? creatorName;
|
||||
final DateTime createdAt;
|
||||
|
||||
const EventItem({
|
||||
required this.id,
|
||||
required this.entityName,
|
||||
required this.description,
|
||||
required this.images,
|
||||
required this.publishTime,
|
||||
this.effectiveTime,
|
||||
this.endTime,
|
||||
required this.popupReminder,
|
||||
required this.status,
|
||||
this.creatorName,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
EventItem copyWith({
|
||||
String? id,
|
||||
String? entityName,
|
||||
String? description,
|
||||
List<String>? images,
|
||||
DateTime? publishTime,
|
||||
DateTime? effectiveTime,
|
||||
DateTime? endTime,
|
||||
bool? popupReminder,
|
||||
String? status,
|
||||
String? creatorName,
|
||||
DateTime? createdAt,
|
||||
}) {
|
||||
return EventItem(
|
||||
id: id ?? this.id,
|
||||
entityName: entityName ?? this.entityName,
|
||||
description: description ?? this.description,
|
||||
images: images ?? this.images,
|
||||
publishTime: publishTime ?? this.publishTime,
|
||||
effectiveTime: effectiveTime ?? this.effectiveTime,
|
||||
endTime: endTime ?? this.endTime,
|
||||
popupReminder: popupReminder ?? this.popupReminder,
|
||||
status: status ?? this.status,
|
||||
creatorName: creatorName ?? this.creatorName,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'entityName': entityName,
|
||||
'description': description,
|
||||
'images': images,
|
||||
'publishTime': publishTime.toIso8601String(),
|
||||
'effectiveTime': effectiveTime?.toIso8601String(),
|
||||
'endTime': endTime?.toIso8601String(),
|
||||
'popupReminder': popupReminder,
|
||||
'status': status,
|
||||
'creatorName': creatorName,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
};
|
||||
|
||||
factory EventItem.fromJson(Map<String, dynamic> json) => EventItem(
|
||||
id: json['id'] ?? '',
|
||||
entityName: json['entityName'] ?? '',
|
||||
description: json['description'] ?? '',
|
||||
images: json['images'] != null ? List<String>.from(json['images']) : [],
|
||||
publishTime: DateTime.tryParse(json['publishTime'] ?? '') ?? DateTime.now(),
|
||||
effectiveTime: json['effectiveTime'] != null
|
||||
? DateTime.tryParse(json['effectiveTime'])
|
||||
: null,
|
||||
endTime: json['endTime'] != null ? DateTime.tryParse(json['endTime']) : null,
|
||||
popupReminder: json['popupReminder'] ?? false,
|
||||
status: json['status'] ?? 'draft',
|
||||
creatorName: json['creatorName'],
|
||||
createdAt: DateTime.tryParse(json['createdAt'] ?? '') ?? DateTime.now(),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user