GeofenceEvent constructor
GeofenceEvent(
- Map params
Implementation
GeofenceEvent(Map params) {
identifier = params['identifier'];
action = params['action'];
timestamp = params['timestamp'];
// (WO-049) The location keeps its `geofence`: Location builds a GeofenceTrigger from it, which
// cannot recurse, so there is nothing to strip.
location = Location(params['location']);
extras = params['extras'];
Map geofenceData = params['geofence'];
// Normalize numeric fields.
final double? radius = _ensureDouble(geofenceData['radius']);
final double? latitude = _ensureDouble(geofenceData['latitude']);
final double? longitude = _ensureDouble(geofenceData['longitude']);
final int? loiteringDelay = _ensureInt(geofenceData['loiteringDelay']);
// Normalize vertices: List<List<double>>
List<List<double>> vertices = [];
if (geofenceData['vertices'] != null) {
List<Object?> tmp = geofenceData['vertices'];
tmp.forEach((vertex) {
final coords = vertex as List;
vertices.add(
coords.map((e) => _ensureDouble(e) ?? 0.0).toList(),
);
});
}
geofence = Geofence(
identifier: geofenceData['identifier'],
radius: radius,
latitude: latitude,
longitude: longitude,
notifyOnEntry: geofenceData['notifyOnEntry'],
notifyOnExit: geofenceData['notifyOnExit'],
notifyOnDwell: geofenceData['notifyOnDwell'],
loiteringDelay: loiteringDelay,
vertices: vertices,
extras: (geofenceData['extras'] != null)
? geofenceData['extras'].cast<String, dynamic>()
: {},
);
// 🔹 Hydrate readonly runtime fields from native payload.
if (geofenceData['hits'] != null) {
geofence.hits = _ensureInt(geofenceData['hits']) ?? 0;
}
if (geofenceData['entryState'] != null) {
geofence.entryState = _ensureInt(geofenceData['entryState']) ?? 0;
}
if (geofenceData['stateUpdatedAt'] != null) {
geofence.stateUpdatedAt = _ensureDouble(geofenceData['stateUpdatedAt']);
}
}