startAnnotationChangedListener function

CancelListener startAnnotationChangedListener(
  1. AnnotationChangedListener listener
)

Listens for when there has been a change to annotations in the document.

var annotChangedCancel = startAnnotationChangedListener((action, annotations) {
  print('flutter annotation action: $action');
  for (Annot annot in annotations) {
    print('annotation has id: ${annot.id}');
    print('annotation is in page: ${annot.pageNumber}');
  }
});

Returns a function that can cancel the listener.

Implementation

CancelListener startAnnotationChangedListener(
    AnnotationChangedListener listener) {
  var subscription = _annotationChangedChannel
      .receiveBroadcastStream(eventSinkId.annotationChangedId.index)
      .listen((annotationsWithActionString) {
    dynamic annotationsWithAction = jsonDecode(annotationsWithActionString);
    String action = annotationsWithAction[EventParameters.action];
    List<dynamic> annotations = Platform.isIOS
        ? jsonDecode(annotationsWithAction[EventParameters.annotations])
        : annotationsWithAction[EventParameters.annotations];
    List<Annot> annotList = new List<Annot>.empty(growable: true);
    for (dynamic annotation in annotations) {
      annotList.add(new Annot.fromJson(annotation));
    }
    listener(action, annotList);
  }, cancelOnError: true);

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