Files
floodwatch/lib/model/flood_station.dart

42 lines
1.1 KiB
Dart

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<String, dynamic> 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<dynamic>) return value[0];
return '';
}
}