Chernarussian
Chernarussian

Reputation: 45

Flutter - interactive ListTile in ListView

I have a problem with my ListView, essentially what I would like to do is an interactable ListTile. I would like the user to click on the tile and via navigator move them to another page.

Something like this works with buttons (onPressed) but doesn't work with ListTiles:

Navigator.of(context).pushNamed(HomePage.tag);

I've tried using OnTap but I can't figure out a way of using that.

final list = ListView(
  children: <Widget>[
    ListTile(
      leading: Icon(Icons.account_circle),
      title: Text('Barrack Obama'),
    ),
    ListTile(
      leading: Icon(Icons.account_circle),
      title: Text('Neil Armstrong'),
      onTap: ,
    ),
    ListTile(
      leading: Icon(Icons.account_circle),
      title: Text('Ivan Ivanovich Ivanov'),
    ),

  ],
);

The list itself is very simple and a test, I'm trying to redirect users when they click on the tile via navigator.

Upvotes: 0

Views: 6177

Answers (1)

diegoveloper
diegoveloper

Reputation: 103421

This should work

  ListTile(
      leading: Icon(Icons.account_circle),
      title: Text('Neil Armstrong'),
      onTap: (){
        Navigator.of(context).pushNamed("your_route_name");
      } ,
    ),

Upvotes: 4

Related Questions