Json 颤振列表视图条件仅显示列表中的第一项

Json 颤振列表视图条件仅显示列表中的第一项,json,flutter,dart,Json,Flutter,Dart,我对颤振和飞镖的开发还很陌生。 我试图在JSON列表中显示符合特定条件的所有项的列表,在本例中,这些条件是一种酒精。我在ListBuilder返回的内容的顶部创建了一个IF语句,但它只在符合条件时返回列表中的第一项。例如,我有三个对象,其中类别为“Rum”,但它仍然只返回第一个。任何帮助或建议都将不胜感激!谢谢大家! class CocktailCategoryList extends StatefulWidget { @override _CocktailListState

我对颤振和飞镖的开发还很陌生。 我试图在JSON列表中显示符合特定条件的所有项的列表,在本例中,这些条件是一种酒精。我在ListBuilder返回的内容的顶部创建了一个IF语句,但它只在符合条件时返回列表中的第一项。例如,我有三个对象,其中类别为“Rum”,但它仍然只返回第一个。任何帮助或建议都将不胜感激!谢谢大家!

    class CocktailCategoryList extends StatefulWidget {
 
  @override
  _CocktailListState createState() => _CocktailListState();
}

class _CocktailListState extends State<CocktailCategoryList> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: Container(
        height: 55,
        width: 55,
        child: FittedBox(
          child: Container(
            height: 60,
            width: 60,
            child: FloatingActionButton(
              backgroundColor: Color.fromRGBO(86, 99, 255, 100),
              onPressed: () {
                
              },
              child: Icon(
                Icons.shuffle,
                color: Colors.white,
                size: 35,
              ),
            ),
          ),
        ),
      ),
      floatingActionButtonLocation:
          FloatingActionButtonLocation.miniCenterDocked,
      bottomNavigationBar: BottomAppBar(
        elevation: 20,
        shape: CircularNotchedRectangle(),
        child: Container(
          height: 55,
          child: Row(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              IconButton(
                iconSize: 30,
                padding: EdgeInsets.only(left: 28),
                icon: Icon(
                  Icons.home,
                ),
                onPressed: () {
                  Navigator.pop(context);
                },
              ),
              IconButton(
                iconSize: 30,
                padding: EdgeInsets.only(right: 28),
                icon: Icon(
                  Icons.list,
                  color: Colors.purple[700],
                ),
                onPressed: () {},
              ),
              IconButton(
                iconSize: 30,
                padding: EdgeInsets.only(left: 28),
                icon: Icon(Icons.person),
                onPressed: () {},
              ),
              IconButton(
                iconSize: 30,
                padding: EdgeInsets.only(right: 28),
                icon: Icon(Icons.search),
                onPressed: () {},
              ),
            ],
          ),
        ),
      ),
      appBar: AppBar(
        backgroundColor: Colors.white,
        iconTheme: IconThemeData(
          color: Colors.black,
        ),
        centerTitle: true,
        title: Text(
          "Cocktails",
          style: TextStyle(color: Colors.black),
        ),
      ),
      body: Center(
        child: FutureBuilder(
          builder: (context, snapshot) {
            var cocktailData = json.decode(snapshot.data.toString());
            return ListView.builder(
              itemCount: cocktailData == null ? 0 : cocktailData.length,
              itemBuilder: (BuildContext context, int index) {
               if (cocktailData[index]['category'] == "Rum"){ 
                  Column(
                  children: [
                    SafeArea(
                      minimum: EdgeInsets.fromLTRB(15, 0, 15, 0),
                      child: GestureDetector(
                        onTap: () => Navigator.push(
                            context,
                            MaterialPageRoute(
                                builder: (context) => CocktailPage(
                                      cocktailData[index]['name'],
                                      cocktailData[index]['subtitle'],
                                      cocktailData[index]['category'],
                                      cocktailData[index]['instructions'],
                                      cocktailData[index]['image'],
                                      cocktailData[index]['ingredients'],
                                    ))),
                        child: Container(
                          width: MediaQuery.of(context).size.width,
                          child: Wrap(children: [
                            Image(
                              image: NetworkImage(cocktailData[index]['image']),
                            ),
                          ]),
                        ),
                      ),
                    ),
                    GestureDetector(
                      onTap: () => Navigator.push(
                          context,
                          MaterialPageRoute(
                              builder: (context) => CocktailPage(
                                    cocktailData[index]['name'],
                                    cocktailData[index]['subtitle'],
                                    cocktailData[index]['category'],
                                    cocktailData[index]['instructions'],
                                    cocktailData[index]['image'],
                                    cocktailData[index]['ingredients'],
                                  ))),
                      child: ListTile(
                        visualDensity:
                            VisualDensity(horizontal: 0, vertical: -1),
                        title: Row(
                          children: [
                            Text(
                              cocktailData[index]['name'],
                              style: TextStyle(fontWeight: FontWeight.bold),
                            ),
                            SizedBox(
                              width: 5,
                            ),
                            CategoryTag(
                                cocktailData[index]['category']) //Button Here
                          ],
                        ),
                        subtitle: Text(cocktailData[index]['subtitle']),
                      ),
                    ),
                    SizedBox(height: 10)
                  ],
                );
                }else {
                  SizedBox();
                }
                
              }
            );
          },
          future:
              DefaultAssetBundle.of(context).loadString('assets/testJson.json'),
        ),
      ),
    );
  }
}
class CocktailCategoryList扩展了StatefulWidget{
@凌驾
_CocktailListState createState()=>\u CocktailListState();
}
类_CocktailListState扩展状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
浮动操作按钮:容器(
身高:55,
宽度:55,
孩子:FittedBox(
子:容器(
身高:60,
宽度:60,
子:浮动操作按钮(
背景颜色:颜色。来自RGBO(86,99,255,100),
已按下:(){
},
子:图标(
图标。洗牌,
颜色:颜色,白色,
尺码:35,
),
),
),
),
),
浮动操作按钮位置:
FloatingActionButtonLocation.miniCenterDocked,
bottomNavigationBar:BottomAppBar(
海拔:20,
形状:CircularNotchedRectangle(),
子:容器(
身高:55,
孩子:排(
mainAxisSize:mainAxisSize.max,
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
图标按钮(
iconSize:30,
填充:仅限边缘设置(左:28),
图标:图标(
我的家,
),
已按下:(){
Navigator.pop(上下文);
},
),
图标按钮(
iconSize:30,
填充:仅限边缘设置(右:28),
图标:图标(
图标列表,
颜色:颜色。紫色[700],
),
按下:(){},
),
图标按钮(
iconSize:30,
填充:仅限边缘设置(左:28),
图标:图标(Icons.person),
按下:(){},
),
图标按钮(
iconSize:30,
填充:仅限边缘设置(右:28),
图标:图标(Icons.search),
按下:(){},
),
],
),
),
),
appBar:appBar(
背景颜色:Colors.white,
iconTheme:IconThemeData(
颜色:颜色,黑色,
),
标题:对,
标题:正文(
“鸡尾酒”,
样式:TextStyle(颜色:Colors.black),
),
),
正文:中(
孩子:未来建设者(
生成器:(上下文,快照){
var cocktailData=json.decode(snapshot.data.toString());
返回ListView.builder(
itemCount:cocktailData==null?0:cocktailData.length,
itemBuilder:(构建上下文,int索引){
如果(cocktailData[索引]['category']==“Rum”){
纵队(
儿童:[
安全区(
最小值:LTRB(15,0,15,0)的边缘设置,
儿童:手势检测器(
onTap:()=>Navigator.push(
上下文
材料路线(
生成器:(上下文)=>CocktailPage(
cocktailData[索引]['name'],
cocktailData[索引]['subtitle'],
cocktailData[索引][“类别”],
cocktailData[索引][“指令”],
cocktailData[索引][“图像”],
cocktailData[索引][“成分”],
))),
子:容器(
宽度:MediaQuery.of(context).size.width,
子对象:包裹(子对象:[
形象(
图像:NetworkImage(cocktailData[索引]['image']),
),
]),
),
),
),
手势检测器(
onTap:()=>Navigator.push(
上下文
材料路线(
生成器:(上下文)=>CocktailPage(
cocktailData[索引]['name'],
cocktailData[索引]['subtitle'],
cocktailData[索引][“类别”],
cocktailData[索引][“指令”],
cocktailData[索引][“图像”],
cocktailData[索引][“成分”],
))),
孩子:ListTile(
视觉密度:
视觉密度(水平:0,垂直:-1),
标题:世界其他地区(
儿童:[
正文(
cocktailData[索引]['name'],
样式:TextStyle(fontWeight:fontWeight.bold),
),
大小盒子(
宽度:5,
),