doShow function

void doShow({
  1. required BuildContext context,
  2. required String screen,
  3. required Config config,
  4. required Map keys,
  5. String? type,
  6. bool showNextAndPreviousButtons = false,
})

Implementation

void doShow({
  required BuildContext context,
  required String screen,
  required Config config,
  required Map<dynamic, dynamic> keys,
  String? type,
  bool showNextAndPreviousButtons = false,
}) async {
  try {
    await Pref.writeBool('disposed', false);

    PagePilot.init(tourStyles: config.styles);
    var jsonResponse;

    var response = await Pref.read("data");

    //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 != "null") {
        jsonResponse = jsonDecode(response);
      }
    }

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

      if (tooltips.any((element) => element["slug"] == screen)) {
        var tooltip =
            tooltips.where((element) => element["slug"] == screen).first;
        DataModel tooltipModel =
            DataModel.fromJson(tooltip, [StepModel.fromJson(tooltip["step"])]);
        if (tooltipModel.slug == screen) {
          showWidget(
            "tooltip",
            tooltipModel,
            config,
            context,
          );
        }
        tooltips.removeWhere((element) => element["slug"] == screen);
      }

      if (tours.any((element) => element["slug"] == screen)) {
        var tour = tours.where((element) => element["slug"] == screen).first;
        List<StepModel> steps = [];
        for (int i = 0; i < tour["steps"].length; i++) {
          steps.add(StepModel.fromJson(tour["steps"][i]));
        }
        DataModel tourModel = DataModel.fromJson(tour, steps);
        if (tourModel.slug == screen) {
          showWidget("tour", tourModel, config, context,
              showNextAndPreviousButtons: showNextAndPreviousButtons,
              keys: keys);
        }
        tours.removeWhere((element) => element["slug"] == screen);
      }

      if (tours.isNotEmpty || tooltips.isNotEmpty) {
        await Pref.write(
            "data", jsonEncode({"tours": tours, "tooltips": tooltips}));
      }
    }
  } catch (e) {
    debugPrint(e.toString());
  }
}