This commit is contained in:
Rishad7594
2026-03-11 20:13:13 +05:30
parent 0e57e7a61c
commit d536d287cd
14 changed files with 2158 additions and 345 deletions

View File

@@ -51,6 +51,14 @@ class EventModel {
final String? eventStatus;
final String? cancelledReason;
// Geo / location fields
final double? latitude;
final double? longitude;
final String? locationName;
// Structured important info list [{title, value}, ...]
final List<Map<String, String>> importantInfo;
EventModel({
required this.id,
required this.name,
@@ -70,8 +78,36 @@ class EventModel {
this.venueName,
this.eventStatus,
this.cancelledReason,
this.latitude,
this.longitude,
this.locationName,
this.importantInfo = const [],
});
/// Safely parse a double from backend (may arrive as String or num)
static double? _parseDouble(dynamic raw) {
if (raw == null) return null;
if (raw is num) return raw.toDouble();
if (raw is String) return double.tryParse(raw);
return null;
}
/// Safely parse important_info from backend (list of {title, value} maps)
static List<Map<String, String>> _parseImportantInfo(dynamic raw) {
if (raw is List) {
return raw.map<Map<String, String>>((e) {
if (e is Map) {
return {
'title': (e['title'] ?? '').toString(),
'value': (e['value'] ?? '').toString(),
};
}
return {'title': '', 'value': e.toString()};
}).toList();
}
return [];
}
factory EventModel.fromJson(Map<String, dynamic> j) {
final imgs = <EventImageModel>[];
if (j['images'] is List) {
@@ -99,6 +135,10 @@ class EventModel {
venueName: j['venue_name'] as String?,
eventStatus: j['event_status'] as String?,
cancelledReason: j['cancelled_reason'] as String?,
latitude: _parseDouble(j['latitude']),
longitude: _parseDouble(j['longitude']),
locationName: j['location_name'] as String?,
importantInfo: _parseImportantInfo(j['important_info']),
);
}
}