Detect focused widget in flutter listview
Asked Answered
R

1

7

I have an horizontal listview.builder widget, each child in the list is about 90℅ of the total width, how can I detect which widget is in focus.

This is my the widget.

new ListView.builder(
                              scrollDirection: Axis.horizontal,
                              itemCount: categories.length,
                              itemBuilder: (context, index) {
                                return new InkWell(
                                  onTap: () {
                                    Navigator
                                        .of(context)
                                        .push(new MaterialPageRoute(
                                          builder: (_) => new StakePage(),
                                        ));
                                  },
                                  child: new Card(
                                    child: new Container(
                                      decoration: new BoxDecoration(
                                        image: new DecorationImage(
                                          fit: BoxFit.cover,
                                          image: categories[index].cover,
                                          colorFilter: new ColorFilter.mode(
                                              Colors.black12,
                                              BlendMode.screen),
                                        ),
                                      ),
                                      constraints: new BoxConstraints(
                                          maxWidth: 400.0,
                                          maxHeight: 600.0),
                                      height: size.height / 2,
                                      width: size.width * 0.85,
                                    ),
                                  ),
                                );
                              }),

It looks like this

Reprieve answered 18/8, 2018 at 12:19 Comment(8)
can you share the code ? image ?Mera
I think you should use PageController and PageView instead of ListView : docs.flutter.io/flutter/widgets/PageController-class.htmlSynergetic
This wouldn't help, I need a scrollableReprieve
What do you mean? PageView is scrollable , you have an example here: gist.github.com/collinjackson/4fddbfa2830ea3ac033e34622f278824Synergetic
I see what you mean, but it has to be a list like the one in the shot, not one widget per page. I already solved it. I'll post the answer in a bitReprieve
@Reprieve can you please post your answer as I'm facing the same issueGarfieldgarfinkel
How did you solve it?Gremlin
@Reprieve can you please post your answer? I need to achieve something like that.Benenson
L
-1

You can wrap your widget with the visibility_detector widget, it will trigger a callback as soon as your widget is visible in the screen.

Lomasi answered 11/6, 2021 at 5:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.