pageViewDisposeEvent method

Future<void> pageViewDisposeEvent(
  1. double heights,
  2. double onScollDepth
)

Implementation

Future<void> pageViewDisposeEvent(double heights, double onScollDepth) async {
  if (_messageBodyPageView.pageLength == 0 ||
      _messageBodyPageView.pageLength == null) {
    _messageBodyPageView.pageLength = heights.toInt();
  }

  var anonId = await CoreDb.instance().getAnonId();
  anonId ??= '${Uuid().v4()}';
  _messageBodyPageView.anonId = anonId;
  if (_messageBodyPageView.scrollDepth == 0 ||
      _messageBodyPageView.scrollDepth == null) {
    _messageBodyPageView.scrollDepth = onScollDepth.toInt();
  }
  int idealTime = 0;
  if (Constants.totalIdleTimeSpent == 0) {
    idealTime = Constants.idleTimeSpent;
    if (idealTime < 10) {
      idealTime = 0;
    }
  } else {
    if (Constants.idleTimeSpent > 10) {
      idealTime = Constants.totalIdleTimeSpent;
    }
  }
  int? totalTimeSpend = Constants.totalTime;


  int activeTime = totalTimeSpend - idealTime;
  if (activeTime < 0) {
    activeTime *= -1;
  }
  _messageBodyPageView.idleTimeSpent = idealTime;
  _messageBodyPageView.activeTimeSpent = activeTime;
  _messageBodyPageView.totalTimeSpent = totalTimeSpend;
  _messageBodyPageView.unlockedStatus = Constants.sessionExists;
  _messageBodyPageView.accessType = Constants.accessType;
  Constants.totalTime = 0;
  Constants.idleTimeSpent = 0;
  Constants.totalIdleTimeSpent = 0;

  _timer?.cancel();

  var paywallViewEvent = PageViewEvent(messageBody: [_messageBodyPageView]);
  paywallViewEvent.topic = "demoTopic";
  final headers = {'Content-Type': 'application/json'};
  Map<String, dynamic> body = paywallViewEvent.toJson();
  String jsonBody = json.encode(body);
  final encoding = Encoding.getByName('utf-8');
  var response = await http.post(
    Uri.parse('${APIMode.EVENT_BASE_URL}/collect/event'),
    headers: headers,
    body: jsonBody,
    encoding: encoding,
  );

}