more detailed flood station info
This commit is contained in:
@@ -1,17 +1,41 @@
|
||||
class FloodStation {
|
||||
final String id;
|
||||
final String town;
|
||||
final double? latestReading;
|
||||
final double lat;
|
||||
final double long;
|
||||
final DateTime? dateOpened;
|
||||
final String catchmentName;
|
||||
final String label;
|
||||
|
||||
FloodStation({
|
||||
required this.id,
|
||||
required this.town,
|
||||
this.latestReading,
|
||||
required this.lat,
|
||||
required this.long,
|
||||
this.dateOpened,
|
||||
required this.catchmentName,
|
||||
required this.label,
|
||||
});
|
||||
|
||||
factory FloodStation.fromMap(Map<String, dynamic> json) => FloodStation(
|
||||
id: json['@id'] ?? '',
|
||||
id: json['wiskiID'] ?? '',
|
||||
town: json['town'] ?? '',
|
||||
latestReading: double.tryParse(json['latestReading']?.toString() ?? ''),
|
||||
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 '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user