-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecreation_area.dart
More file actions
52 lines (48 loc) · 2.05 KB
/
Copy pathrecreation_area.dart
File metadata and controls
52 lines (48 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import 'package:kb4yg/models/parking_lot.dart';
import 'fire_danger.dart';
/// Collection of parking lots.
class RecreationArea {
final String name;
/// Description of recreation area.
final String info;
/// HATEOAS link to parking lot details.
final String parkingLotUrl;
/// Web address of associated nature images.
final List<String> imageUrls;
/// ALl parking lots in recreation area.
final List<ParkingLot> parkingLots;
/// General parking spots available amongst parking lots.
late final int spots =
[for (var x in parkingLots) x.spots].fold(0, (p, c) => p + c);
/// Handicap parking spots available amongst parking lots.
late final int handicap =
[for (var x in parkingLots) x.handicap].fold(0, (p, c) => p + c);
/// Least recent timestamp (time updated) amongst parking lots.
late final DateTime dt = [for (var x in parkingLots) x.dt]
.fold(parkingLots[0].dt, (p, c) => p.isAfter(c) ? c : p);
/// Highest fire danger level amongst parking lots in recreation area.
// Create a list of FireDanger objects in each parking lot & compares to find
// highest threat
late final FireDanger fireDanger = [for (var x in parkingLots) x.fireDanger]
.fold(parkingLots[0].fireDanger,
(p, c) => p.level.index > c.level.index ? p : c);
/// Construct [RecreationArea] from JSON object.
/// Required fields:
/// - RecreationArea (string)
/// - About (string)
/// - Images (array of strings)
/// - List (array of [ParkingLot] objects)
RecreationArea.fromJson(Map<String, dynamic> json)
: name = json['RecreationArea'],
info = json['About'],
parkingLotUrl = json['List'][0]['ParkURL'],
imageUrls = List<String>.from(json['Images']),
parkingLots = [
for (var item in json['List']) ParkingLot.fromJson(item)
] {
// Alphabetize parking lots by name
parkingLots.sort((loc1, loc2) => loc1.name.compareTo(loc2.name));
}
String get spotsStr => spots < 0 ? 'n/a' : spots.toString();
String get handicapStr => handicap < 0 ? 'n/a' : handicap.toString();
}