doShow function

void doShow({
  1. required BuildContext context,
  2. required String screen,
  3. required Config config,
  4. String? type,
})

Implementation

void doShow({
  required BuildContext context,
  required String screen,
  required Config config,
  String? type,
}) async {
  try {
    PagePilot.initStyles(config.styles);
    var jsonResponse;

    var response = await http.get(
      Uri.parse("$baseUrl/get/unacknowledged?userId=${Config.userId}"),
    );

    //mock data
    if (type != null) {
      jsonResponse = {
        "type": type,
        "content": {
          "shape": "react", //rect or circle
          // "element": "#dialog",
          // "element": "#tooltip",
          "element": "#beacon",
          "title": "This is title",
          "body": "this is the body of ${type}",
          // "tour": [
          //   {
          //     "title": "This is title",
          //     // "description": "this is the body of ${type}",
          //     "body": "this is the body of ${type}",
          //   },
          // ],//why extra tour array required ????
          "tourContent": [
            {
              "element": "#dialog",
              "shape": "rect",
              "title": "This is title",
              "body": "this is the body of ${type}",
              "type": "dialog",
            },
            {
              "element": "#tooltip",
              "shape": "rect",
              "title": "This is title",
              "body": "this is the body of ${type}",
              "type": "tooltip",
            }
          ],
        }
      };
    } else {
      if (response.body != "null") {
        jsonResponse = jsonDecode(response.body);
      }
    }

    if (response.body != "null") {
      String? title = jsonResponse["content"]["title"];
      String? body = jsonResponse["content"]["body"];
      String? url = jsonResponse["content"]["url"];

      if (jsonResponse["screen"].toString().toLowerCase() ==
          screen.toLowerCase()) {
        if ((title != null && body != null) || url != null) {
          showWidget(context, jsonResponse, config);
        } else {
          throw Exception(
            "PagePilotPluginError: Either provide title & body or html for ${jsonResponse["content"]["element"].toString()}",
          );
        }
      }
    }
  } catch (e) {
    print(e);
  }
}