prepareLocationDataAndSend method
Future<void>
prepareLocationDataAndSend(
- LocationNotificationModel notification,
- LatLng myLocation
Implementation
Future<void> prepareLocationDataAndSend(
LocationNotificationModel notification, LatLng myLocation) async {
var isSend = false;
if (notification.to == null) {
isSend = true;
} else if ((DateTime.now().difference(notification.from!) >
Duration(seconds: 0)) &&
(notification.to!.difference(DateTime.now()) > Duration(seconds: 0))) {
isSend = true;
}
if (isSend) {
var atkeyMicrosecondId = notification.key!.split('-')[1].split('@')[0];
var atKey = newAtKey(
5000, 'locationnotify-$atkeyMicrosecondId', notification.receiver,
ttl: (notification.to != null)
? notification.to!.difference(DateTime.now()).inMilliseconds
: null);
var newLocationNotificationModel = LocationNotificationModel()
..atsignCreator = notification.atsignCreator
..receiver = notification.receiver
..isAccepted = notification.isAccepted
..isAcknowledgment = notification.isAcknowledgment
..isExited = notification.isExited
..isRequest = notification.isRequest
..isSharing = notification.isSharing
..from = DateTime.now()
..to = notification.to
..lat = myLocation.latitude
..long = myLocation.longitude
..key = 'locationnotify-$atkeyMicrosecondId';
try {
await atClient!.put(
atKey,
LocationNotificationModel.convertLocationNotificationToJson(
newLocationNotificationModel),
isDedicated: MixedConstants.isDedicated,
);
} catch (e) {
print('error in sending location: $e');
}
}
}