processOfflineEvents method

Future<void> processOfflineEvents()

Implementation

Future<void> processOfflineEvents() async {
  // Retrieve offline events from secure storage
  print("processOfflineEvent");
  String? allEvents = await _secureStorage.read(key: 'offlineEvents');
  print(allEvents);

  if (allEvents != null) {
    _offlineEvents = List<Map<String, dynamic>>.from(json.decode(allEvents));

    if (_offlineEvents.isEmpty) {
      return;
    }
    print(_offlineEvents);
    // Process the offline events
    await bulkSendEvent(_offlineEvents);

    // Clear the offline events from secure storage
    await _secureStorage.write(key: 'offlineEvents', value: json.encode([]));
  }

  //Clear the offlineEvents list in memory
  _offlineEvents.clear();
}