getEvents function

Implementation

Future<List<EventNotificationModel>?> getEvents() async {
  var allEvents = <EventNotificationModel>[];
  var regexList = await EventService().atClientInstance!.getKeys(
        regex: 'createevent-',
      );

  if (regexList.isEmpty) {
    // EventService().allEvents = allEvents;
    // EventService().eventListSink.add(allEvents);
    return [];
  }

  try {
    for (var i = 0; i < regexList.length; i++) {
      var atkey = EventService().getAtKey(regexList[i]);
      var atValue = await EventService().atClientInstance!.get(atkey);
      if (atValue.value != null) {
        var event = EventNotificationModel.fromJson(jsonDecode(atValue.value));
        allEvents.add(event);
      }
    }

    WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
      // EventService().allEvents = allEvents;
      // EventService().eventListSink.add(allEvents);
    });
    return allEvents;
  } catch (e) {
    print(e);
    return null;
  }
}