skip to Main Content

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?

2

Answers


  1. Return the widget in itemBuilder

    body: ListView.builder(
            itemCount: menu.length,
            itemBuilder: (BuildContext context, int index) {
              return menu[index];
    
            },
          ),
    
    Login or Signup to reply.
  2. You Just need to Return menuListItem

     import 'package:flutter/material.dart';
        
        class MenuList extends StatefulWidget {
          @override
          _MenuListState createState() => _MenuListState();
        }
        
        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 menuListItem = menu[index];
                  return menuListItem;
                },
              ),
            );
          }
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search