Flutter return list of categorise tabs and items

Viewed 249

Im new to flutter, Im trying to implement menu as in this example https://pub.dev/packages/scrollable_list_tabview, I have food array in structure like below, so I need to show the categories in the horizontal tabs, and the food items in the vertical list, so I need to show the items under its category label as well as under its category tab, I think it should be grouped by category id, but I don't know how to do it, also I set the hight(expandedHeight: 600,) manually but Im sure there is away to make it automatically, please help

enter image description here

                SliverAppBar( // <-- app bar for custom sticky menu
                    backgroundColor: Colors.white,
                    automaticallyImplyLeading: false,
                    elevation: 0.0,
                    expandedHeight: 600,
                    // <-- doesn't work for minimum height setup
                    flexibleSpace: ScrollableListTabView(
                      tabHeight: 50,
                      bodyAnimationDuration: const Duration(milliseconds: 150),
                      tabAnimationCurve: Curves.easeOut,
                      tabAnimationDuration: const Duration(milliseconds: 200),
                      tabs: [
                        ScrollableListTab(
                            tab: ListTab(
                                label: Text('Label 1'),
                                icon: Icon(Icons.group),
                                showIconOnList: false),
                            body: ListView.builder(
                              shrinkWrap: true,
                              physics: NeverScrollableScrollPhysics(),
                              itemCount: _con.categories.length,
                               itemBuilder: (context, index) {
                                return ListTile(
                                  leading: Container(
                                    height: 40,
                                    width: 40,
                                    decoration: BoxDecoration(
                                        shape: BoxShape.circle,
                                        color: Colors.grey),
                                    alignment: Alignment.center,
                                    child: Text(index.toString()),
                                  ),
                                  title: Text('List element $index'),
                                );

                              }
                            ))
                      ],
                    ),
                ),

Array Structure:

  "data": [
      {
        "id": 1,
        "name": "American fried rice",
        "price": 11,
        "category_id": 1,
        "category": {
          "id": 1,
          "name": "Grains",
        },
      },


      {
        "id": 5,
        "name": "Pizza Valtellina",
        "price": 7.4,
        "category_id": 1,
       
        "category": {
          "id": 1,
          "name": "Grains",
          "has_media": true,
        },
      },
     
      }
    ],
1 Answers
Related