首页 > 解决方案 > 如何使列表视图中的每个项目作为列颤动

问题描述

我在flutter中的listview工作,因为我是flutter的新开发人员,所以在设计listview时遇到了一些困难。现在列表和我一起工作,如下:

1

现在它是 Row 所有数据都被视为 Row 或一行。我试着让它像列中的每个项目一样作为单独的列。所以将第一个列图像作为中心,第二个列文本,第三个列文本,从上到下。

这是我的代码:

@override
  Widget build(BuildContext context) {
    String getID;
    getID=  widget.itemHolder.toString();
    return FutureBuilder<List<Flowerdata>>(
                future: fetchFlowers(),
              builder: (context, snapshot) {

                if (!snapshot.hasData) return Center(
                    child: CircularProgressIndicator()
                );
                return ListView(
                  children: snapshot.data.map((data) => Column(children: <Widget>[
                    GestureDetector(
                      onTap: ()=>{getItemAndNavigate(data.id ,context)
                      },
                      child: Row(
                          children: [
                            Container(
                                width: 100,
                                height: 100,
                                margin: EdgeInsets.fromLTRB(10, 0, 10, 0),
                                child: ClipRRect(
                                    borderRadius: BorderRadius.circular(8.0),
                                    child:
                                    Image.network(data.ImageURL,
                                      width: 200, height: 100, fit: BoxFit.cover,))),

                            Flexible(child:
                            Text(data.Name,
                                style: TextStyle(fontSize: 18)
                            )
                            ),
                            Flexible(child:
                            Text(data.SendFrom,
                                style: TextStyle(fontSize: 18)
                            )
                            ),

                             FloatingActionButton(
                              onPressed: () {

                                Navigator.push(context, MaterialPageRoute(builder: (context) => AddComments( UserPostID: UserPostID,psoid:psoid.toString()),));
                              },

                              child: Icon(Icons.add),
                            ),
                          ]

                      ),
                    ),

                    Divider(color: Colors.black),

                  ],))
                      .toList(),

                );
              },
            );

  }
}

如果有人知道问题的解决方案,请帮助我。

标签: flutter

解决方案


尝试这个

 return ListView(
          children: [
            for (var data in snapshot.data)
              GestureDetector(
                child: Column(
                  children: [
                    Row(),
                    Text(data),
                    Text(data),
                    Text(data),
                  ],
                ),
              )
          ],
        );

或者

 return ListView(
          children: [
            snapshot.data.map((data) => GestureDetector(
                  child: Column(
                    children: [
                      Row(),
                      Text(data),
                      Text(data),
                      Text(data),
                    ],
                  ),
                ))
          ],
        );

推荐阅读