listen method Null safety

void listen()

Starts listening for events.

Implementation

void listen() {
  app.onServiceEvent.listen((map) {
    if (map.containsKey(path)) {
      var event = map[path]!;

      _onAllEvents.add(event);

      if (event.eventName == indexedEvent) {
        var d = event.data;
        var transformed = WebSocketEvent(
            eventName: event.eventName,
            data: d is Iterable ? d.map(deserialize).toList() : null);
        if (transformed.data != null) {
          _onIndexed.add(transformed.data!);
        }
        return;
      }

      var transformed = transformEvent(event).data;

      switch (event.eventName) {
        case readEvent:
          _onRead.add(transformed);
          break;
        case createdEvent:
          _onCreated.add(transformed);
          break;
        case modifiedEvent:
          _onModified.add(transformed);
          break;
        case updatedEvent:
          _onUpdated.add(transformed);
          break;
        case removedEvent:
          _onRemoved.add(transformed);
          break;
      }
    }
  });
}