Search code examples
flutterdartlistview

How to display nested list items in a listview builder


How do i present the elements of the list below in one view in flutter using the listview builder.

The list below has nested list. its length is two.

[[{name: beans, quantity: 20, {name:beans, quantity: 10}], [ {name:rice, quantity:5}]]

I need to display the three items in one listview builder as displayed down below it will be displayed thus

  1. name: beans quantity: 20

    name: beans quantity: 10


  1. name: rice quantity: 5


Solution

  • You can achieve this like this:

    List lists = [["list1"],["list2"]];
    
     return ListView(
              children: [
                for (var list in lists)
                  for (var element in list) ListTile(title: element),
              ],
            );