trySendTrackingGrantedEventToBeacon method
send the tracking granted event to beacon, if there is no event sent yet and the tracking is granted and there is no request in progress. In the future, we can add a retry mechanism if the request fails.
Implementation
Future<void> trySendTrackingGrantedEventToBeacon(
WHERE_CALLED_FROM called_from) async {
if (_tblAttBeaconEventHolder.didSendEventToBeacon) {
return;
}
if (await _tblTrackingManager.isTrackingGranted &&
_tblAttBeaconEventHolder.currentBeaconRequestStatus !=
CurrentRequestStatus.IN_PROGRESS) {
_tblAttBeaconEventHolder.first_time_where_called_from = called_from;
_tblAttBeaconEventHolder.currentBeaconRequestStatus =
CurrentRequestStatus.IN_PROGRESS;
_tblBeaconHandler.sendBeaconEvent(
TBLAttBeaconEvent(_tblAttBeaconEventHolder.where_called_from),
onSuccess: () {
_tblAttBeaconEventHolder.currentBeaconRequestStatus =
CurrentRequestStatus.SUCCESS;
_tblAttBeaconEventHolder.didSendEventToBeacon = true;
print(
"Sent event to Beacon: first_where_called_from: $WHERE_CALLED_FROM.INIT");
}, onFailure: (e) {
_tblAttBeaconEventHolder.currentBeaconRequestStatus =
CurrentRequestStatus.FAILURE;
TBLLogger.logException('Failed to send event to Beacon: $e');
});
}
}