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

How to get current index value? #21

Closed
newbieflutter opened this issue Mar 24, 2020 · 4 comments
Closed

How to get current index value? #21

newbieflutter opened this issue Mar 24, 2020 · 4 comments

Comments

@newbieflutter
Copy link

Hi,
I have tried to use you library but now I am stucked here.

controller.addListener(() {
print("Now which index we are in "+controller.position.pixels.toString());
});
I have set listener I notice you cant get what is the current index which I have scroll too.

Another thing.
return (BuildContext context, int index) {
//
return Card(
child: Container(
//height: heights[index % 527],
color: (index == 0) ? Colors.red : Colors.green,
child: Center(child: Text('ITEM $index')),
),
);
};

How is this build I dont see any for loop or any list array here?

@marcglasberg
Copy link
Owner

Sorry, I am not able to understand your question.

@newbieflutter
Copy link
Author

Hi Marc,
Sorry for my question. Let me rewrite it.

  1. See now you have jumpTo, indexTo etc function which is very good. Now my question is as I am scrolling can I know at which index I have reached or at which index item I am at now?

  2. How is return (BuildContext context, int index) { is created I dont see any loop function ?

Hope I am clearer now ?

@marcglasberg
Copy link
Owner

Ok:

  1. Sorry, you can't. Not with this widget and not with a regular ListView. If you don't need an infinite scrolling I suggest you use https://pub.dev/packages/scrollable_positioned_list which has the feature you want.

  2. The loop is implicit. Supposte the indexed_list_view needs to show items 5, 6 and 7 in the screen. It will then call this builder function 3 times. First with index==5, second with index==6, and a third time with index==7. This is a builder pattern and is very common with flutter. In other words, just make sure that function returns the correct widget for each given index.

@newbieflutter
Copy link
Author

Hi Marc,
Let me explore it. Thank you for help and details.

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

2 participants