init static method

void init(
  1. String apiKey,
  2. String userId, {
  3. String endpoint = '',
})

Implementation

static void init(String apiKey, String userId, {String endpoint = ''}) {
  try {
    BasicMessageChannel<dynamic> channel =
    const BasicMessageChannel("plotline", JSONMessageCodec());
    channel.setMessageHandler((message) async {
      Map<String, dynamic> messageMap = message;
      switch (messageMap["method"]) {
        case "getAllElements":
          double pixRatio = double.parse(messageMap["pixelRatio"].toString());
          getAllElements(messageMap["listenerId"], pixRatio,
              messageMap["screenWidth"], messageMap["screenHeight"]);
          break;
        case "areViewsPresent":
          double pixRatio = double.parse(messageMap["pixelRatio"].toString());
          areViewsPresent(
              messageMap["listenerId"],
              messageMap["searchElements"],
              pixRatio,
              messageMap["screenWidth"],
              messageMap["screenHeight"]);
          break;
        case "getViewPosition":
          double pixRatio = double.parse(messageMap["pixelRatio"].toString());
          getViewPosition(
              messageMap["listenerId"],
              messageMap["clientElementId"],
              pixRatio,
              messageMap["screenWidth"],
              messageMap["screenHeight"]);
          break;
        case "setPlotlineEventsListener":
          try {
            _callback(messageMap["eventName"], messageMap["properties"]);
          } catch (e) {
            debugPrint("Error in passing Plotline Events: $e");
          }
          break;
      }
    });

    if (endpoint.isNotEmpty) {
      plotlineChannel.invokeMethod('init', <String, dynamic>{
        'apiKey': apiKey,
        'userId': userId,
        'endpoint': endpoint
      });
    } else {
      plotlineChannel.invokeMethod('init', <String, dynamic>{
        'apiKey': apiKey,
        'userId': userId,
      });
    }
  } catch (e) {
    debugPrint("Error in init: $e");
  }
}