Search code examples
flutterdartweb

How to create several ListTile inside a List and prompt them out in ListView?


Below is the code what I did, but it perform nothing.

class _MenuListState extends State<MenuList> {

  List<ListTile> menu = [
    ListTile(
      leading: Icon(Icons.featured_play_list),
      title: Text('Playlists'),
    ),
    ListTile(
      leading: Icon(Icons.send),
      title: Text('Menu...'),
    ),
    ListTile(
      leading: Icon(Icons.logout),
      title: Text('Logout'),
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView.builder(
        itemCount: menu.length,
        itemBuilder: (BuildContext context, int index) {
          final menuList = menu[index];
          
        },
      ),
    );
  }
}

As mentioned as title, how can I let the code perform that the screen prompt out all the ListTile inside the List?


Solution

  • Return the widget in itemBuilder

    body: ListView.builder(
            itemCount: menu.length,
            itemBuilder: (BuildContext context, int index) {
              return menu[index];
    
            },
          ),