addMember method
we are assuming that the _newLocationDataModel has a new share id
if it has a same id already in [allAtsignsLocationData_newLocationDataModel.receiver
]
then we won't add it again
Implementation
Future<void> addMember(LocationDataModel _newLocationDataModel) async {
if (allAtsignsLocationData[_newLocationDataModel.receiver] != null) {
/// don't add and send again if already present
var _receiverLocationDataModel =
allAtsignsLocationData[_newLocationDataModel.receiver]!;
if (_newLocationDataModel.locationSharingFor.keys.isEmpty) {
return;
}
var _id = _newLocationDataModel.locationSharingFor.keys.first;
if (_receiverLocationDataModel.locationSharingFor[_id] != null) {
return;
}
}
// add
_appendLocationDataModelData([_newLocationDataModel]);
var locationDataModel = getLocationDataModel(_newLocationDataModel
.receiver); // get updated (aggregated LocationDataModel)
if (locationDataModel == null) {
return;
}
var myLocation = await getMyLocation();
if (myLocation != null) {
await prepareLocationDataAndSend(
locationDataModel.receiver, locationDataModel, myLocation);
if (!masterSwitchState) {
/// method from main app
if (locationPromptDialog != null) {
// _appendLocationDataModelData([locationDataModel]);
locationPromptDialog!();
/// return as when main switch is turned on, it will send location to all.
return;
}
}
} else {
// ignore: unnecessary_null_comparison
if (AtLocationNotificationListener().navKey != null) {
CustomToast().show('Location permission not granted',
AtLocationNotificationListener().navKey.currentContext!,
isError: true);
}
}
}