Visitor constructor

Visitor(
  1. FlagshipConfig config,
  2. String visitorId,
  3. bool _isAuthenticated,
  4. Map<String, Object> context,
  5. bool _hasConsented,
  6. OnFlagStatusChanged? _onFlagStatusChanged,
  7. OnFlagStatusFetchRequired? _onFlagStatusFetchRequired,
  8. OnFlagStatusFetched? _onFlagStatusFetched,
)

Implementation

Visitor(
    this.config,
    this.visitorId,
    this._isAuthenticated,
    Map<String, Object> context,
    this._hasConsented,
    this._onFlagStatusChanged,
    this._onFlagStatusFetchRequired,
    this._onFlagStatusFetched) {
  if (_isAuthenticated == true) {
    this.anonymousId = FlagshipTools.generateFlagshipId();
  } else {
    anonymousId = null;
  }

  // Init Tracking manager
  switch (config.trackingManagerConfig.batchStrategy) {
    case BatchCachingStrategy.BATCH_CONTINUOUS_CACHING:
      trackingManager = TrackingManageContinuousStrategy(
          Service(http.Client()),
          config.trackingManagerConfig,
          this.config.hitCacheImp ?? DefaultCacheHitImp());
      break;
    case BatchCachingStrategy.BATCH_PERIODIC_CACHING:
      trackingManager = TrackingManagerPeriodicStrategy(
          Service(http.Client()),
          config.trackingManagerConfig,
          this.config.hitCacheImp ?? DefaultCacheHitImp());
      break;
    default:
      trackingManager = TrackingManager(Service(http.Client()),
          config.trackingManagerConfig, DefaultCacheHitImp());
      break;
  }

  // Load preset_Context
  this.updateContextWithMap(FlagshipContextManager.getPresetContextForApp());

  // Update context
  this.updateContextWithMap(context);

  // Set delegate
  _visitorDelegate = VisitorDelegate(this);

  // Set the consent
  _hasConsented; //= hasConsented;

  // Load the hits in cache if exist
  _visitorDelegate.lookupHits();

  // Lookup for the cached visitor data
  _visitorDelegate.lookupVisitor(this.visitorId).then((isLoadedFromCache) => {
        this._fetchReasons = isLoadedFromCache
            ? FetchFlagsRequiredStatusReason.FLAGS_FETCHED_FROM_CACHE
            : FetchFlagsRequiredStatusReason.FLAGS_NEVER_FETCHED
      });
  _visitorDelegate.lookupVisitor(this.visitorId).whenComplete(() {});

  /// Send the consent hit
  _visitorDelegate.sendHit(Consent(hasConsented: _hasConsented));

  DataUsageTracking.sharedInstance()
      .configureDataUsageWithVisitor(null, this);
}