addMember method

Future<void> addMember(
  1. LocationNotificationModel? notification
)

Implementation

Future<void> addMember(LocationNotificationModel? notification) async {
  if (atsignsToShareLocationWith
          .indexWhere((element) => element!.key == notification!.key) >
      -1) {
    return;
  }

  var myLocation = await getMyLocation();
  if (myLocation != null) {
    if (masterSwitchState) {
      await prepareLocationDataAndSend(notification!, myLocation);

      if (MixedConstants.isDedicated) {
        // ignore: unawaited_futures
        SyncSecondary().callSyncSecondary(SyncOperation.syncSecondary);
      }
    } else {
      /// method from main app
      if (locationPromptDialog != null) {
        atsignsToShareLocationWith.add(notification);
        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!);
    }
  }

  // add
  atsignsToShareLocationWith.add(notification);
  print(
      'after adding atsignsToShareLocationWith length ${atsignsToShareLocationWith.length}');
}