startAnnotationMenuPressedListener function

CancelListener startAnnotationMenuPressedListener(
  1. AnnotationMenuPressedChannelListener listener
)

Listens for presses on annotation menu items that has been passed into Config.overrideAnnotationMenuBehavior.

var annotationMenuPressedCancel = startAnnotationMenuPressedListener((annotationMenuItem, annotations) {
  print('Annotation menu item ' + annotationMenuItem + ' has been pressed');
  for (Annot annotation in annotations) {
    print('Annotation has id: ${annotation.id}');
    print('Annotation is in page: ${annotation.pageNumber}');
  }
});

Returns a function that can cancel the listener.

Implementation

CancelListener startAnnotationMenuPressedListener(
    AnnotationMenuPressedChannelListener listener) {
  var subscription = _annotationMenuPressedChannel
      .receiveBroadcastStream(eventSinkId.annotationMenuPressedId.index)
      .listen((annotationMenuString) {
    dynamic annotationMenuObject = jsonDecode(annotationMenuString);
    dynamic annotationMenuItem =
        annotationMenuObject[EventParameters.annotationMenuItem];
    dynamic annotations = annotationMenuObject[EventParameters.annotations];
    List<Annot> annotList = new List<Annot>.empty(growable: true);
    for (dynamic annotation in annotations) {
      annotList.add(Annot.fromJson(annotation));
    }
    listener(annotationMenuItem, annotList);
  }, cancelOnError: true);

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