Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to listen to the current index which is in the viewport? #70

Open
mark8044 opened this issue Nov 19, 2021 · 2 comments
Open

Comments

@mark8044
Copy link

Is there a way to listen to the current index which is in the viewport?

This could be very useful to trigger actions when an index is inside the viewport

@jerrywell
Copy link
Member

refer to https://github.com/quire-io/scroll-to-index/blob/master/lib/scroll_to_index.dart#L481,

the concept is that you will get the offset to reveal the target widget based on alignment 0 and 1 (means the top and bottom of the viewport).

the code should be like: (never really try it in code, you can follow this concept doing the experiment)

final isInViewport = _offsetToRevealInViewport(10, 0) => 0 && _offsetToRevealInViewport(10, 0) <= 0;

@LinXunFeng
Copy link

The flutter_scrollview_observer package can help you.

ListViewObserver(
  child: _buildListView(),
  onObserve: (resultModel) {
    print('firstChild.index -- ${resultModel.firstChild?.index}');
    print('displaying -- ${resultModel.displayingChildIndexList}');
  },
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants