From c10d02470096dd9511676a5b5186827f1c21a401 Mon Sep 17 00:00:00 2001 From: Zohaib Kambrani Date: Thu, 10 Dec 2020 18:21:10 +0300 Subject: [PATCH] no message --- lib/uitl/HMG_Geofence.dart | 45 +++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/lib/uitl/HMG_Geofence.dart b/lib/uitl/HMG_Geofence.dart index b17d9269..53c25090 100644 --- a/lib/uitl/HMG_Geofence.dart +++ b/lib/uitl/HMG_Geofence.dart @@ -93,9 +93,18 @@ class HMG_Geofence { static void transitionTrigger(List id, Location location, GeofenceEvent event) async { id.forEach((element) { - final SendPort send = IsolateNameServer.lookupPortByName(_isolatePortName); - send?.send(event.toString()); + LocalNotification.showNow( + title: "GeofenceEvent: ${event.toString()}", + subtitle: element, + onClickNotification: (payload) { + debugPrint(payload); + }, + payload: element); }); + // id.forEach((element) { + // final SendPort send = IsolateNameServer.lookupPortByName(_isolatePortName); + // send?.send({"event": event, "geofence_id": element}); + // }); } void _registerIsolatePort() { @@ -103,18 +112,38 @@ class HMG_Geofence { AppSharedPreferences pref = AppSharedPreferences(); var jsonString = pref.getString(HMG_GEOFENCES); List jsonList = json.decode(jsonString); - jsonList.forEach((element) { - - }) + List geoList = jsonList.map((e) => GeoZonesResponseModel().fromJson(e)); port.listen((dynamic data) { + GeofenceEvent event = data["event"]; + String geofence_id = data["geofence_id"]; + + GeoZonesResponseModel geofence = _findByGeofenceIdFrom(geoList, geofence_id); + LocalNotification.showNow( - title: "HMG-Geofence", - subtitle: element, + title: "GeofenceEvent: ${_nameOf(event)}", + subtitle: geofence.description, onClickNotification: (payload) { debugPrint(payload); }, - payload: "Zohaib Kambrani"); + payload: json.encode(geofence.toJson())); }); } + + GeoZonesResponseModel _findByGeofenceIdFrom(List list, String geofence_id) { + var have = list.where((element) => element.geofenceId() == geofence_id).toList().first; + return have; + } + + String _nameOf(GeofenceEvent event) { + if (event == GeofenceEvent.exit) { + return "Exit"; + } else if (event == GeofenceEvent.enter) { + return "Enter"; + } else if (event == GeofenceEvent.dwell) { + return "Well"; + } else { + event.toString(); + } + } }