toMap method

Map? toMap()

Implementation

Map? toMap() {
  if (_map != null) {
    return _map;
  }

  Map config = {};

  // 1) Add compound groups first.
  final _compound = compoundToMap();
  if (_compound.isNotEmpty) {
    config.addAll(_compound);

    // Flat mirrors for legacy consumers.
    final app = _compound['app'] as Map<String, dynamic>?;
    if (app != null) {
      final notif = app['notification'];
      if (notif != null) config['notification'] = notif;

      final rationale = app['backgroundPermissionRationale'];
      if (rationale != null) {
        config['backgroundPermissionRationale'] = rationale;
      }
    }
  }

  // Were we provided a Transistor token?  Auto-config the url and authorization.
  if (transistorAuthorizationToken != null) {
    if (http != null) {
      http!.url = transistorAuthorizationToken!.locationsUrl;
    } else {
      url = transistorAuthorizationToken!.locationsUrl;
    }
    authorization = transistorAuthorizationToken!.authorizationConfig;
  }

  // Geolocation Options
  if (desiredAccuracy != null) config['desiredAccuracy'] = desiredAccuracy;
  if (distanceFilter != null) config['distanceFilter'] = distanceFilter;
  if (stationaryRadius != null) config['stationaryRadius'] = stationaryRadius;
  if (locationTimeout != null) config['locationTimeout'] = locationTimeout;
  if (disableElasticity != null) {
    config['disableElasticity'] = disableElasticity;
  }
  if (elasticityMultiplier != null) {
    config['elasticityMultiplier'] = elasticityMultiplier;
  }
  if (stopAfterElapsedMinutes != null) {
    config['stopAfterElapsedMinutes'] = stopAfterElapsedMinutes;
  }
  if (geofenceProximityRadius != null) {
    config['geofenceProximityRadius'] = geofenceProximityRadius;
  }
  if (maxMonitoredGeofences != null) {
    config['maxMonitoredGeofences'] = maxMonitoredGeofences;
  }
  if (geofenceInitialTriggerEntry != null) {
    config['geofenceInitialTriggerEntry'] = geofenceInitialTriggerEntry;
  }
  if (desiredOdometerAccuracy != null) {
    config['desiredOdometerAccuracy'] = desiredOdometerAccuracy;
  }
  if (useSignificantChangesOnly != null) {
    config['useSignificantChangesOnly'] = useSignificantChangesOnly;
  }
  // ActivityRecognition
  if (isMoving != null) {
    config['isMoving'] = isMoving;
  }
  if (stopTimeout != null) {
    config['stopTimeout'] = stopTimeout;
  }
  if (activityRecognitionInterval != null) {
    config['activityRecognitionInterval'] = activityRecognitionInterval;
  }
  if (minimumActivityRecognitionConfidence != null) {
    config['minimumActivityRecognitionConfidence'] =
        minimumActivityRecognitionConfidence;
  }
  if (disableStopDetection != null) {
    config['disableStopDetection'] = disableStopDetection;
  }
  if (stopOnStationary != null) {
    config['stopOnStationary'] = stopOnStationary;
  }
  // HTTP & Persistence
  if (url != null) {
    config['url'] = url;
  }
  if (persistMode != null) {
    config['persistMode'] = persistMode;
  }
  if (method != null) {
    config['method'] = method;
  }
  if (httpRootProperty != null) {
    config['httpRootProperty'] = httpRootProperty;
  }
  if (params != null) {
    config['params'] = params;
  }
  if (headers != null) {
    config['headers'] = headers;
  }
  if (extras != null) {
    config['extras'] = extras;
  }
  if (autoSync != null) {
    config['autoSync'] = autoSync;
  }
  if (disableAutoSyncOnCellular != null) {
    config['disableAutoSyncOnCellular'] = disableAutoSyncOnCellular;
  }
  if (disableProviderChangeRecord != null) {
    config['disableProviderChangeRecord'] = disableProviderChangeRecord;
  }
  if (autoSyncThreshold != null) {
    config['autoSyncThreshold'] = autoSyncThreshold;
  }
  if (batchSync != null) {
    config['batchSync'] = batchSync;
  }
  if (maxBatchSize != null) {
    config['maxBatchSize'] = maxBatchSize;
  }
  if (locationTemplate != null) {
    config['locationTemplate'] = locationTemplate;
  }
  if (geofenceTemplate != null) {
    config['geofenceTemplate'] = geofenceTemplate;
  }
  if (maxDaysToPersist != null) {
    config['maxDaysToPersist'] = maxDaysToPersist;
  }
  if (maxRecordsToPersist != null) {
    config['maxRecordsToPersist'] = maxRecordsToPersist;
  }
  if (locationsOrderDirection != null) {
    config['locationsOrderDirection'] = locationsOrderDirection;
  }
  if (httpTimeout != null) {
    config['httpTimeout'] = httpTimeout;
  }
  if (authorization != null) {
    config['authorization'] = authorization!.toMap();
  }
  // Application
  if (stopOnTerminate != null) {
    config['stopOnTerminate'] = stopOnTerminate;
  }
  if (startOnBoot != null) {
    config['startOnBoot'] = startOnBoot;
  }
  if (heartbeatInterval != null) {
    config['heartbeatInterval'] = heartbeatInterval;
  }
  if (schedule != null) {
    config['schedule'] = schedule;
  }
  if (scheduleUseAlarmManager != null) {
    config['scheduleUseAlarmManager'] = scheduleUseAlarmManager;
  }
  // Logging & Debug
  if (debug != null) {
    config['debug'] = debug;
  }
  if (logLevel != null) {
    config['logLevel'] = logLevel;
  }
  if (logMaxDays != null) {
    config['logMaxDays'] = logMaxDays;
  }
  if (reset != null) {
    config['reset'] = reset;
  }
  ////
  // iOS Options
  //

  // Geolocation Options
  if (pausesLocationUpdatesAutomatically != null) {
    config['pausesLocationUpdatesAutomatically'] =
        pausesLocationUpdatesAutomatically;
  }
  if (locationAuthorizationRequest != null) {
    config['locationAuthorizationRequest'] = locationAuthorizationRequest;
  }
  if (locationAuthorizationAlert != null) {
    config['locationAuthorizationAlert'] = locationAuthorizationAlert;
  }
  if (disableLocationAuthorizationAlert != null) {
    config['disableLocationAuthorizationAlert'] =
        disableLocationAuthorizationAlert;
  }
  if (showsBackgroundLocationIndicator != null) {
    config['showsBackgroundLocationIndicator'] =
        showsBackgroundLocationIndicator;
  }
  // Activity Recognition Options
  if (activityType != null) {
    config['activityType'] = activityType;
  }
  if (stopDetectionDelay != null) {
    config['stopDetectionDelay'] = stopDetectionDelay;
  }
  if (disableMotionActivityUpdates != null) {
    config['disableMotionActivityUpdates'] = disableMotionActivityUpdates;
  }
  // Application Options
  if (preventSuspend != null) {
    config['preventSuspend'] = preventSuspend;
  }
  ////
  // Android Options
  //

  // Geolocation Options
  if (locationUpdateInterval != null) {
    config['locationUpdateInterval'] = locationUpdateInterval;
  }
  if (fastestLocationUpdateInterval != null) {
    config['fastestLocationUpdateInterval'] = fastestLocationUpdateInterval;
  }
  if (deferTime != null) {
    config['deferTime'] = deferTime;
  }
  if (allowIdenticalLocations != null) {
    config['allowIdenticalLocations'] = allowIdenticalLocations;
  }
  if (enableTimestampMeta != null) {
    config['enableTimestampMeta'] = enableTimestampMeta;
  }
  if (speedJumpFilter != null) {
    config['speedJumpFilter'] = speedJumpFilter;
  }
  // Activity Recognition Options
  if (triggerActivities != null) {
    config['triggerActivities'] = triggerActivities;
  }
  if (motionTriggerDelay != null) {
    config['motionTriggerDelay'] = motionTriggerDelay;
  }
  if (geofenceModeHighAccuracy != null) {
    config['geofenceModeHighAccuracy'] = geofenceModeHighAccuracy;
  }
  // Application Options
  if (enableHeadless != null) {
    config['enableHeadless'] = enableHeadless;
  }

  if (backgroundPermissionRationale != null) {
    config['backgroundPermissionRationale'] =
        backgroundPermissionRationale!.toMap();
  }
  if (notification != null) {
    config['notification'] = notification!.toMap();
  }
  return config;
}