AvoBatcher constructor

AvoBatcher({
  1. required SharedPreferences sharedPreferences,
  2. required AvoNetworkCallsHandler networkCallsHandler,
  3. required AvoSessionTracker sessionTracker,
  4. required String avoInstallationId,
})

Implementation

AvoBatcher(
    {required this.sharedPreferences,
    required this.networkCallsHandler,
    required this.sessionTracker,
    required this.avoInstallationId})
    : this._batchFlushAttemptTimestamp =
          DateTime.now().millisecondsSinceEpoch {
  _events = sharedPreferences
          .getStringList(diskBatcherStorageCacheKey)
          ?.map((String savedItem) {
        Map<String, dynamic> eventMap = jsonDecode(savedItem);
        if (eventMap["type"] == "sessionStarted") {
          return SessionStartedBody.fromJson(eventMap);
        } else {
          return EventSchemaBody.fromJson(eventMap);
        }
      }).toList() ??
      [];

  _checkIfBatchNeedsToBeSent();
}