synchronizeModifications method

  1. @override
Future<void> synchronizeModifications()
override

Synchronize modification for the visitor

Implementation

@override
Future<void> synchronizeModifications() async {
  Flagship.logger(Level.ALL, SYNCHRONIZE_MODIFICATIONS);
  Status state = Flagship.getStatus();
  try {
    var camp = await visitor.decisionManager.getCampaigns(
        Flagship.sharedInstance().envId ?? "",
        visitor.visitorId,
        visitor.anonymousId,
        visitor.getConsent(),
        visitor.getContext());
    // Clear the previous modifications
    visitor.modifications.clear();
    // Update panic value
    visitor.decisionManager.updatePanicMode(camp.panic);
    if (camp.panic) {
      state = Status.PANIC_ON;
    } else {
      state = Status.READY;
      var modif = visitor.decisionManager.getModifications(camp.campaigns);
      visitor.modifications.addAll(modif);
      Flagship.logger(
          Level.INFO,
          SYNCHRONIZE_MODIFICATIONS_RESULTS.replaceFirst(
              "%s", "${visitor.modifications.keys}"));
    }
    // Update the state for Flagship
    visitor.flagshipDelegate.onUpdateState(state);
  } catch (error) {
    Flagship.logger(Level.EXCEPTIONS,
        EXCEPTION.replaceFirst("%s", "${error.toString()}"));
  }
  return;
}