showWidget function

void showWidget(
  1. String type,
  2. String id,
  3. List<StepModel> data,
  4. Config config,
  5. BuildContext context,
)

Implementation

void showWidget(String type, String id, List<StepModel> data, Config config,
    BuildContext context) async {
  String? shape,
      title,
      body,
      url,
      position,
      color,
      background,
      textColor,
      selector;
  int? scale;
  GlobalKey? key;
  bool showConfetti = false, isDraggable = false;
  if (type != "tour") {
    shape = data[0].shape ?? "rect";

    title = data[0].title;
    body = data[0].content;
    background = data[0].background ?? "#ffffff";
    textColor = data[0].textColor ?? "#000000";
    showConfetti = data[0].showConfetti ?? false;

    url = data[0].url;
    //TODO adjust scale from frontend(cs) first
    scale = null;
    // scale =
    //     int.tryParse(jsonResponse["content"]["bodyHtmlScale"].toString());
    isDraggable = data[0].draggable ?? false;
    position = data[0].position;
    color = data[0].color;
    selector = data[0].selector;
    key = config.keys[selector.toString()];
  }

  PagePilot.showConfetti = showConfetti;

  if (((body != null) || url != null) || type == "tour") {
    switch (type) {
      case "tooltip":
      case "i":
      case "?":
        if (key == null) {
          throw Exception(
            "PagePilotPluginError: Key not found for ${selector.toString()}",
          );
        }
        PagePilot.showTooltip(
          context,
          shape: shape ?? "rect",
          key: key,
          scale: scale,
          background: background,
          textColor: textColor,
          // title: jsonResponse["content"]["tour"][0]["title"],
          // description: jsonResponse["content"]["tour"][0]["description"],
          title: title,
          body: body ?? "",
        );
        await acknowledge(id);
        break;
      case "tour":
      case "walktrough":

        //KEYCHANGE: "description" => "body"
        PagePilot.showTour(context, config,
            tours: data, scrollController: config.scrollController);

        await acknowledge(id);
        break;

      /*case "dialog":
        PagePilot.showOkDialog(
          context,
          shape: shape ?? "rect",
          title: title,
          body: body,
          background: background,
          textColor: textColor,
          url: url,
          scale: scale,
          onOkPressed: () async {
            await http.get(
              Uri.parse(
                "$baseUrl/acknowledge?id=${jsonResponse["_id"]}",
              ),
            );
          },
        );
        break;
      case "snackbar":
      case "snack":
      case "toast":
        PagePilot.showSnackbar(
          context,
          title: title,
          body: body,
          background: background,
          textColor: textColor,
          url: url,
          scale: scale,
          duration: int.tryParse(jsonResponse["timeout"].toString()) ?? 3000,
        );
        //acknowledge
        await http.get(
          Uri.parse(
            "$baseUrl/acknowledge?id=${jsonResponse["_id"]}",
          ),
        );
        break;
      case "bottomsheet":
        PagePilot.showBottomSheet(
          context,
          title: title,
          body: body,
          background: background,
          textColor: textColor,
          url: url,
          scale: scale,
          onOkPressed: () async {
            await http.get(
              Uri.parse(
                "$baseUrl/acknowledge?id=${jsonResponse["_id"]}",
              ),
            );
          },
        );
        break;
      // case "spotlight":
      //   break;
      case "pip":
      case "floatingwidget":
        PagePilot.showFloatingWidget(
          context,
          title: title,
          body: body,
          background: background,
          textColor: textColor,
          url: url,
          position: position,
          scale: scale,
          isDraggable: isDraggable,
          isVisible: true,
        );
        await http.get(
          Uri.parse(
            "$baseUrl/acknowledge?id=${jsonResponse["_id"]}",
          ),
        );
        break;
      case "beacon":
        if (key == null) {
          throw Exception(
            "PagePilotPluginError: Key not found for ${jsonResponse["content"]["element"].toString()}",
          );
        }
        PagePilot.showBeacon(
          context,
          shape: shape ?? "rect",
          key: key,
          beaconPosition: position == null ? "center" : position.toLowerCase(),
          title: title,
          body: body ?? "",
          background: background,
          textColor: textColor,
          color: color == null
              ? Colors.blue.withOpacity(0.5)
              : PagePilot.hexToColor(color),
          onBeaconClicked: () async {
            //acknowledge
            await http.get(
              Uri.parse(
                "$baseUrl/acknowledge?id=${jsonResponse["_id"]}",
              ),
            );
          },
          // title: jsonResponse["content"]["tour"][0]["title"],
          // description: jsonResponse["content"]["tour"][0]["description"],
        );

        break;*/
    }
  } else {
    throw Exception(
      "PagePilotPluginError: Either provide title & body or html for ${type}  and key: ${data[0].selector.toString()}",
    );
  }
}