startPageChangedListener function

CancelListener startPageChangedListener(
  1. PageChangedListener listener
)

Listens for when the current page is changed in the viewer.

var pageChangedCancel = startPageChangedListener((previousPageNumber, pageNumber) {
  print('flutter page changed. from $previousPageNumber to $pageNumber');
});

Returns a function that can cancel the listener.

Implementation

CancelListener startPageChangedListener(PageChangedListener listener) {
  var subscription = _pageChangedChannel
      .receiveBroadcastStream(eventSinkId.pageChangedId.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();
  };
}