startAnnotationsSelectedListener function

CancelListener startAnnotationsSelectedListener(
  1. AnnotationsSelectedListener listener
)

Listens for when annotations are selected.

var annotsSelectedCancel = startAnnotationsSelectedListener((annotationWithRects) {
  for (AnnotWithRect annotWithRect in annotationWithRects) {
    print('annotation has id: ${annotWithRect.id}');
    print('annotation is in page: ${annotWithRect.pageNumber}');
    print('annotation has width: ${annotWithRect.rect.width}');
  }
});

Returns a function that can cancel the listener.

Implementation

CancelListener startAnnotationsSelectedListener(
    AnnotationsSelectedListener listener) {
  var subscription = _annotationsSelectedChannel
      .receiveBroadcastStream(eventSinkId.annotationsSelectedId.index)
      .listen((annotationWithRectsString) {
    List<dynamic> annotationWithRects = jsonDecode(annotationWithRectsString);
    List<AnnotWithRect> annotWithRectList =
        new List<AnnotWithRect>.empty(growable: true);
    for (dynamic annotationWithRect in annotationWithRects) {
      annotWithRectList.add(new AnnotWithRect.fromJson(annotationWithRect));
    }
    listener(annotWithRectList);
  }, cancelOnError: true);

  return () {
    subscription.cancel();
  };
}