class FloodStation { final String id; final String town; final double lat; final double long; final DateTime? dateOpened; final String catchmentName; final String label; FloodStation({ required this.id, required this.town, required this.lat, required this.long, this.dateOpened, required this.catchmentName, required this.label, }); factory FloodStation.fromMap(Map json) => FloodStation( id: json['wiskiID'] ?? '', town: json['town'] ?? '', lat: parseDoubleValue(json['lat']), long: parseDoubleValue(json['long']), dateOpened: DateTime.tryParse(json['dateOpened'] ?? ''), catchmentName: parseStringValue(json['catchmentName']), label: parseStringValue(json['label']), ); static double parseDoubleValue(dynamic value) { if (value is double) return value; if (value is String) return double.parse(value); return 0; } static String parseStringValue(dynamic value) { if (value is String) return value; if (value is List) return value[0]; return ''; } }