0

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.

1 Answer 1

4

This should work

  ListTile(
      leading: Icon(Icons.account_circle),
      title: Text('Neil Armstrong'),
      onTap: (){
        Navigator.of(context).pushNamed("your_route_name");
      } ,
    ),
Sign up to request clarification or add additional context in comments.

5 Comments

I'm getting an error = Could not find a generator for route "chat-page" in the _WidgetsAppState. Even though I have a class created with a String tag
did you defined your routes in MaterialApp ? otherwise check my updated answer
I'm still getting the same error, I've a feeling I might have missed something, although I do not know what. My other navigators seem to be working fine, I'm using tags to navigate to them, This one however still cannot find the generator for route.
Is it using the same materialapp?
I've managed to fix it, I forgot to add the tag to my main.dart. Thank you for the help,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.