startScrollChangedListener function

CancelListener startScrollChangedListener(
  1. ScrollChangedListener listener
)

Listens for when the document's scroll position is changed.

var scrollChangedCancel = startScrollChangedListener((horizontal, vertical) {
  print('flutter scroll position: $horizontal, $vertical');
});

Returns a function that can cancel the listener.

Implementation

CancelListener startScrollChangedListener(ScrollChangedListener listener) {
  var subscription = _scrollChangedChannel
      .receiveBroadcastStream(eventSinkId.scrollChangedId.index)
      .listen((scrollString) {
    dynamic scrollObject = jsonDecode(scrollString);
    dynamic horizontal = scrollObject['horizontal'];
    dynamic vertical = scrollObject['vertical'];
    listener(horizontal, vertical);
  }, cancelOnError: true);

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