本文介绍了Flutter在ListTile中显示sql数据而不是DataCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在显示使用 DataCell
从我的sql数据库中获取的数据的列表,但是我真的不喜欢它的外观,并且想要切换为使用 ListTile 来显示它code>,这是我用来使用
DataCell
:
I am displaying a list of data fetched from my sql database using DataCell
, but I don't really like how it looks and want to switch it to display it using ListTile
, this is the code that I am using to display it using DataCell
:
return SingleChildScrollView(
scrollDirection: Axis.vertical,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(
columns: [
DataColumn(
label: Text(''),
)
],
rows: _chatUsers
.map(
(user) => DataRow(cells: [
DataCell(
Text(user.firstNameUser),
// Add tap in the row and populate the
// textfields with the corresponding values to update
onTap: () {
// Set the Selected employee to Update
_selectedUser = user;
setState(() {
});
},
),
]),
)
.toList(),
),
),
);
推荐答案
您需要使用 ListView 小部件.该API参考部分中有很多解释,我认为您在阅读之后将可以对您的应用程序进行返工.
You need to use the ListView widget for this.There is a lot explained in that API reference section, I think you will be able to rework you app after reading.
因此,您将得到一个 ListView
,其 children
属性设置为
So you will have a ListView
with the children
property set to smth like
_chatUsers
.map(
(user) =>
ListTile(
title: Text(user.firstNameUser),
// Add tap in the row and populate the
// textfields with the corresponding values to update
onTap: () {
// Set the Selected employee to Update
_selectedUser = user;
setState(() {
});
},
),
)
.toList()
这篇关于Flutter在ListTile中显示sql数据而不是DataCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!