initializeLocationService function

void initializeLocationService(
  1. AtClientImpl atClientImpl,
  2. String currentAtSign,
  3. GlobalKey<NavigatorState> navKey, {
  4. required String mapKey,
  5. required String apiKey,
  6. bool showDialogBox = false,
  7. String rootDomain = MixedConstants.ROOT_DOMAIN,
  8. Function? getAtValue,
  9. dynamic streamAlternative(
    1. List<KeyLocationModel>
    )?,
})

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

Implementation

void initializeLocationService(AtClientImpl atClientImpl, String currentAtSign,
    GlobalKey<NavigatorState> navKey,
    {required String mapKey,
    required String apiKey,
    bool showDialogBox = false,
    String rootDomain = MixedConstants.ROOT_DOMAIN,
    Function? getAtValue,
    Function(List<KeyLocationModel>)? streamAlternative}) async {
  /// 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) {
    print('Error in initializeLocationService $e');
  }

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