toMap method

Map<String, Object?> toMap()

Convert chart config info to a map

Implementation

Map<String, Object?> toMap() {
  final configMap = {
    "workspaceKey": workspaceKey,
    "event": eventKey,
    "region": region ?? "eu",
    "language": language ?? "en",
    "holdToken": holdToken ?? "",
    "session": session ?? "none",
    "mode": mode,
    "showLegend": showLegend ?? true,
    "showFullScreenButton": showFullScreenButton ?? true,
    "showMinimap": showMinimap ?? true,
    "inputDevice": inputDevice ?? 'auto',
    "showActiveSectionTooltipOnMobile": showActiveSectionTooltip ?? true,
    "showViewFromYourSeatOnMobile": showViewFromYourSeat ?? true,
    "showSectionContents": showSectionContents ?? "auto",
    "priceFormatter": priceFormatter,
  };

  if (pricing != null) {
    configMap["pricing"] = pricing?.toList();
  }

  if (loading != null) {
    configMap["loading"] = loading;
  }

  if (!showLoadingAnimation) {
    configMap["loading"] = "<div class='loader'></div>";
  }

  if (objectIcon != null) {
    configMap["objectIcon"] = objectIcon;
    if (extraConfig == null) {
      configMap["extraConfig"] = {};
    }
  }

  if (maxSelectedObjectList != null) {
    configMap["maxSelectedObjects"] = maxSelectedObjectList;
  } else if (maxSelectedObjects != null) {
    configMap["maxSelectedObjects"] = maxSelectedObjects;
  }

  if (extraConfig != null) {
    configMap["extraConfig"] = extraConfig!.toMap().toString();
  }

  if (availableCategories != null && availableCategories!.isNotEmpty) {
    configMap["availableCategories"] = availableCategories!.toList();
  }

  if (unavailableCategories != null && unavailableCategories!.isNotEmpty) {
    configMap["unavailableCategories"] = unavailableCategories?.toList();
  }

  if (Platform.isAndroid) {
    configMap["_client"] = "android";
  }

  if (Platform.isIOS) {
    configMap["_library"] = "ios";
  }

  if (numberOfPlacesToSelect != null) {
    configMap["numberOfPlacesToSelect"] = numberOfPlacesToSelect;
  }

  if (selectedObjects != null) {
    configMap["selectedObjects"] = selectedObjects!.map((obj) {
      if (obj.ticketType != null) {
        final Map<String, dynamic> map = {
          "label": obj.label,
          "ticketType": obj.ticketType.toString(),
        };
        if (obj.amount != null) {
          map["amount"] = obj.amount!;
        }
        return map;
      } else {
        return obj.label;
      }
    }).toList();
  }

  return configMap;
}