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/tenant/${Config.tenantId}/client/unacknowledged?userId=${Config.userId}&device=${Platform.operatingSystem}"),
    );

    //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",
              // "description": "this is the body of ${type}",
              "body": "this is the body of $type",
            },
            {
              "element": "#tooltip",
              "shape": "rect",
              "title": "This is title",
              // "description": "this is the body of ${type}",
              "body": "this is the body of $type",
            }
          ],
        }
      };
    } else {
      if (response.body != "null") {
        jsonResponse = jsonDecode(response.body);
      }
    }

    if (response.body != "null") {
      List<dynamic> tours = [];
      List<dynamic> tooltips = [];
      if (jsonResponse["tooltips"].length > 0) {
        tooltips = jsonResponse["tooltips"];
      }
      if (jsonResponse["tours"].length > 0) {
        tours = jsonResponse["tours"];
      }

      tooltips.forEach((tooltip) async {
        String slug = tooltip["slug"];
        if (slug == screen) {
          showWidget(
            "tooltip",
            tooltip["id"],
            [StepModel.fromJson(tooltip["step"])],
            config,
            context,
          );
        }
      });
      tours.forEach((tour) async {
        String slug = tour["slug"];
        List<StepModel> steps = [];
        for (int i = 0; i < tour["steps"].length; i++) {
          steps.add(StepModel.fromJson(tour["steps"][i]));
        }
        if (slug == screen) {
          showWidget(
            "tour",
            tour["id"],
            steps,
            config,
            context,
          );
        }
      });
    }
  } catch (e) {
    debugPrint(e.toString());
  }
}