trackcalled method

Future<void> trackcalled(
  1. Map<String, dynamic> trackdata,
  2. String type
)

Implementation

Future<void> trackcalled(Map<String, dynamic> trackdata, String type) async {
  Map<String, NudgeUi> gameKeyUiMapper = {};

  for (NudgeUi plugin in widget.plugins) {
    gameKeyUiMapper[plugin.type] = plugin;
  }

  for (var campaign in trackdata['campaigns']) {
    if (gameKeyUiMapper[campaign['gameKey']] != null) {
      try {
        await gameKeyUiMapper[campaign['gameKey']]!
            .copyWith(
            id: campaign['gameSettingsId'],
            token: widget.nudgeInstance.token)
            .trigger(
            context: navigatorKey.currentContext!,
            userStatId: campaign['userStatId'] ?? "",
            position: campaign['position'],
            event: type,
            gameSettingDetails: campaign['gameSettings']);
      } catch (e, st) {
        if (widget.log != null) {
          widget.log!(e.toString());
        }
        if (kDebugMode) {
          print(e);
          print(st);
        }
      }
    } else {
      String e = "No plugin found for ${trackdata['gameKey']}, ignoring.";
      if (widget.log != null) {
        widget.log!(e.toString());
      }
      if (kDebugMode) {
        print(e);
      }
    }
  }
}