问题
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(),
),
),
);
回答1:
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.
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()
来源:https://stackoverflow.com/questions/63018841/flutter-display-sql-data-in-listtile-instead-of-datacell