Search code examples
androidflutterlistviewfocusandroid-tv

how to focus on listview items in android tv app on flutter


I want to build an android tv app in flutter almost everything is done but one problem is I'm not able to focus(like some pop-up effect or border change anything that tells the user that you're on this item right now) item we are iterating in Listview.image of what I want in app

but I'm not able to give this focus. I tried with FocusScope -> Listview - > focus node but it is not giving exact behaviour in first and last index, and also it's not working in the homepage where multiple listviews are there.


Solution

  • after trying many ways I found an easy and effective way to doing this using InkWell.

    widget tree will look like => scaffold -> somewidgets -> ListView -> Inkwell -> Carosouls

    we have to wrap widget in InkWell and use onTap , focusColor , onFocusChange in InkWell because InkWell it self having focus.

     onFocusChange: (value) {
                            print(i);
                            setState(() {
                              hoverIndex = i;
                              widget.selectedIndex = i;
                            });
                          },
                          focusColor: Colors.transparent,
    

    this on focus change function will be inside InkWell so it will call everytime user ilterate in ListView so according to that i (index) we can assign hoverIndex and according to hoverIndex we can change styling of ilterating element.