flutter - 如何使列表视图中的每个项目作为列颤动
问题描述
我在flutter中的listview工作,因为我是flutter的新开发人员,所以在设计listview时遇到了一些困难。现在列表和我一起工作,如下:
现在它是 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(),
);
},
);
}
}
如果有人知道问题的解决方案,请帮助我。
解决方案
尝试这个
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),
],
),
))
],
);
推荐阅读
- python - Python C API:T_INT 未在此范围内声明
- java - 无法确定唯一的对象集
- ruby-on-rails - gem 更新导致错误:未定义的方法 ssl_version
- mysql - 我的查询中有一个错误,显示“字段列表中的未知列”
- vue.js - 构建 Vue.js 应用程序时 JavaScript 堆内存不足
- java - Jackson MRBean 不工作,无法构造实例
- c# - C# 更新或向注册表添加值
- unit-testing - 手动创建 JUnit Result 对象
- php - Laravel 5.8 从网址中删除 index.php
- c# - 如何在我的网站中实现任何 asp.net 的源代码用于教程目的