listview - 将卡片设置为 Listview
问题描述
我是新来的颤振。请帮我用卡片列出视图。我从 SQLite 获取数据并将其直接设置为 listview。请让我知道如何在我的代码中添加卡。这是我的代码。
body: FutureBuilder<List<UserModel>>(
future: db.getUserModelData(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Center(child: CircularProgressIndicator());
return ListView(
children: snapshot.data
.map((user) => ListTile(
title: Text(user.name),
subtitle: Text(user.bDate),
leading: CircleAvatar(
backgroundColor: Color(
(math.Random().nextDouble() * 0xFFFFFF)
.toInt() <<
0)
.withOpacity(1.0),
child: Text(user.name[0],
style: TextStyle(
fontSize: 18.0,
color: Colors.white,
)),
),
))
.toList(),
);
},
),
解决方案
我已经用 Column() 解决了我的问题 这是代码
return Column(
children: List.generate(snapshot.data.length, (itemIndex) {
ProfileModel product = snapshot.data[itemIndex];
return Card(
child: ListTile(
leading: SizedBox(
height: 50.0,
width: 50.0,
child: CircleAvatar(
backgroundColor: Color(
(math.Random().nextDouble() * 0xFFFFFF)
.toInt() <<
0)
.withOpacity(1.0),
child: Text(product.name[0],
style: TextStyle(
fontSize: 18.0,
color: Colors.white,
)),
)),
title: Text(product.name),
subtitle: Text(product.bDate + ', ' + product.mobile),
));
}),
);
推荐阅读
- c# - 在 C# 中将单词变成标记值
- unit-testing - 没有在北极狐上注册的仪器
- javascript - firebase 在本机反应中不起作用-expo install firebase
- python-3.x - 如何使用传递给它的字典参数调用functional_call?
- rabbitmq - Terraform 和 RabbitMQ - 启用插件
- model-view-controller - 如何从控制器读取温度值到局部视图。我要返回 JSON,我还可以返回部分视图吗?
- java - 不在不同线程中重新评估昂贵的数据
- android - 关于如何在 Android 中将图像调整为目标文件大小的另一种方法
- java - 无法在 android studio 中运行视频文件
- mysql - MySQL 中具有特定范围的 MAX() 的语法