这是我的代码,从我的 API 中,我将所有类别和食物嵌套在类别中。API 响应
{
"data": {
"getOneRestaurant": {
"error": false,
"msg": "Restaurant Get Successfully",
"data": {
"cover_img": "https://i.ibb.co/YNZ64QG/0-89399200-1551782137-fast1.jpg",
"description": "",
"address": {
"address": "21 KDA Approach Rd, Khulna 9200, Bangladesh"
},
"food_categories": [
{
"_id": "5fa122713cf61557a65d0a12",
"name": "Fast Food",
"foods": [
{
"_id": "5fcc709678070b0098203a0f",
"name": "Chicken reshmi kabab",
"description": "",
"dish_img": "https://i.ibb.co/kHGcn3v/Indian-chicken-kebab-Getty-Images-91279048-58eee4623df78cd3fcd0c6ca.jpg",
"price": 320,
"price_and_size": []
},
{
"_id": "5fcc719178070b0098203a10",
"name": "Kacchi biriyani",
"description": "",
"dish_img": "https://i.ibb.co/Zmp3yp5/47125153f54b972670697f49dac933cc.jpg",
"price": 230,
"price_and_size": []
},
{
"_id": "5fcc722578070b0098203a11",
"name": "Chicken tikka ",
"description": "",
"dish_img": "https://i.ibb.co/M2sLTqP/img-20161210-221320-largejpg.jpg",
"price": 170,
"price_and_size": []
},
{
"_id": "5fcc72f478070b0098203a12",
"name": "Chicken tandoori 1 pcs",
"description": "",
"dish_img": "https://i.ibb.co/LZw5Fp2/chicken-tandori-1526595014.jpg",
"price": 170,
"price_and_size": []
},
{
"_id": "5fce042d78070b0098203b1b",
"name": "Special thai soup for 4 person",
"description": "",
"dish_img": "https://i.ibb.co/YtmVwmm/download.jpg",
"price": 300,
"price_and_size": []
},
{
"_id": "5fce048b78070b0098203b1c",
"name": "Thai clear soup for 4 person",
"description": "",
"dish_img": "https://i.ibb.co/BjcRvNL/tomyum800-56a9498e5f9b58b7d0f9ea4f.jpg",
"price": 250,
"price_and_size": []
},
{
"_id": "5fce04d078070b0098203b1d",
"name": "Chicken vegetables soup four 4 person",
"description": "",
"dish_img": "https://i.ibb.co/ZN3Bxnk/chicken-vegetable-soup-9-1200.jpg",
"price": 180,
"price_and_size": []
},
{
"_id": "5fce050678070b0098203b1e",
"name": "Russian salad",
"description": "",
"dish_img": "https://i.ibb.co/vxh9qGZ/download.jpg",
"price": 200,
"price_and_size": []
},
{
"_id": "5fce053378070b0098203b1f",
"name": "Green salad",
"description": "",
"dish_img": "https://i.ibb.co/XpwwB8Y/green-salad-1200-1387.jpg",
"price": 100,
"price_and_size": []
},
{
"_id": "5fce056878070b0098203b20",
"name": "French fries",
"description": "",
"dish_img": "https://i.ibb.co/NCPsK6Y/Copycat-Mc-Donalds-French-Fries-500x500.jpg",
"price": 60,
"price_and_size": []
},
{
"_id": "5fce059a78070b0098203b21",
"name": "Chicken fry 4 pic",
"description": "",
"dish_img": "https://i.ibb.co/9hwPhgd/download-1.jpg",
"price": 180,
"price_and_size": []
},
{
"_id": "5fce05dc78070b0098203b22",
"name": "Chicken burger",
"description": "",
"dish_img": "https://i.ibb.co/HnJH38T/Butchies-2.jpg",
"price": 80,
"price_and_size": []
},
{
"_id": "5fce060078070b0098203b23",
"name": "Chicken pizza ",
"description": "",
"dish_img": "https://i.ibb.co/WWXzqdk/download.jpg",
"price": 120,
"price_and_size": []
},
{
"_id": "5fce062a78070b0098203b24",
"name": "Chicken naan",
"description": "",
"dish_img": "https://i.ibb.co/cgLg923/download-1.jpg",
"price": 60,
"price_and_size": []
}
]
}
]
}
}
}
}
选项卡
TabBar(
isScrollable: true,
labelPadding: EdgeInsets.symmetric(horizontal: width * 20),
controller: _tabController,
labelColor: Color(0xffC8102E),
unselectedLabelColor: Colors.black,
labelStyle: TextStyle(
fontWeight: FontWeight.bold
),
unselectedLabelStyle: TextStyle(
fontWeight: FontWeight.normal
),
indicatorColor: Color(0xffC8102E),
tabs: profile.foodCategories.map((e) => Tab(text: e.name)).toList(),
)
身体
TabBarView(
controller: _tabController,
children: profile.foodCategories.map((RestaurantFoodCategories e) {
return itemList(e.foods, e.id);
}).toList(),
)
物品清单
Widget itemList(List<RestaurantFoods> items,String id) {
return ListView.builder(
primary: false,
itemCount: items.length ?? 0,
padding: EdgeInsets.zero,
shrinkWrap: true,
physics: AlwaysScrollableScrollPhysics(),
itemBuilder: (context, index){
RestaurantFoods item = items[index];
return itemCard(item, id);
},
);
}