startPageMovedListener function

CancelListener startPageMovedListener(
  1. PageMovedListener listener
)

Listens for when a page has been moved in the document.

var pageMovedCancel = startPageMovedListener((previousPageNumber, pageNumber) {
  print('flutter page moved from $previousPageNumber to $pageNumber');
});

Returns a function that can cancel the listener.

Implementation

CancelListener startPageMovedListener(PageMovedListener listener) {
  var subscription = _pageMovedChannel
      .receiveBroadcastStream(eventSinkId.pageMovedId.index)
      .listen((pagesString) {
    dynamic pagesObject = jsonDecode(pagesString);
    dynamic previousPageNumber =
        pagesObject[EventParameters.previousPageNumber];
    dynamic pageNumber = pagesObject[EventParameters.pageNumber];
    listener(previousPageNumber, pageNumber);
  }, cancelOnError: true);

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