initializeLocationService function

Future<void> initializeLocationService(
  1. GlobalKey<NavigatorState> navKey, {
  2. required String mapKey,
  3. required String apiKey,
  4. bool showDialogBox = false,
  5. String rootDomain = 'root.atsign.org',
  6. Function? getAtValue,
  7. dynamic streamAlternative(
    1. List<KeyLocationModel>
    )?,
  8. bool isEventInUse = false,
})

Function to initialise the package. Should be mandatorily called before accessing package functionalities.

mapKey is needed to access maps.

apiKey is needed to calculate ETA.

Steps to get mapKey/apiKey available in README.

showDialogBox if false dialog box wont be shown.

streamAlternative a function which will return updated lists of KeyLocationModel.

isEventInUse to signify if the events package is used.

Implementation

Future<void> initializeLocationService(GlobalKey<NavigatorState> navKey,
    {required String mapKey,
    required String apiKey,
    bool showDialogBox = false,
    String rootDomain = 'root.atsign.org',
    Function? getAtValue,
    Function(List<KeyLocationModel>)? streamAlternative,
    bool isEventInUse = false}) async {
  final _logger = AtSignLogger('initializeLocationService');

  /// initialise keys
  MixedConstants.setApiKey(apiKey);
  MixedConstants.setMapKey(mapKey);

  try {
    /// So that we have the permission status beforehand & later we dont get
    /// PlatformException(PermissionHandler.PermissionManager) => Multiple Permissions exception
    await Geolocator.requestPermission();
  } catch (e) {
    _logger.severe('Error in requesting location permission: $e');
  }

  /// first get all location-notify keys, mine and others
  SendLocationNotification().reset();
  await SendLocationNotification().getAllLocationShareKeys();
  await MasterLocationService().init(
      AtClientManager.getInstance().atClient.getCurrentAtSign()!,
      AtClientManager.getInstance().atClient,
      newGetAtValueFromMainApp: getAtValue);

  AtLocationNotificationListener().init(navKey, rootDomain, showDialogBox,
      newGetAtValueFromMainApp: getAtValue, isEventInUse: isEventInUse);
  KeyStreamService().init(AtLocationNotificationListener().atClientInstance,
      streamAlternative: streamAlternative);
}