getEventById method

Future<Event?> getEventById(
  1. String id
)

Searches for the event in this timeline. If not found, requests from the server. Requested events are cached.

Implementation

Future<Event?> getEventById(String id) async {
  for (final event in events) {
    if (event.eventId == id) return event;
  }
  if (_eventCache.containsKey(id)) return _eventCache[id];
  final requestedEvent = await room.getEventById(id);
  if (requestedEvent == null) return null;
  _eventCache[id] = requestedEvent;
  return _eventCache[id];
}