简体   繁体   English

Flutter 在 ListTile 而不是 DataCell 中显示 sql 数据

[英]Flutter display sql data in ListTile instead of 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 :我正在使用DataCell显示从我的 sql 数据库中获取的数据列表,但我不太喜欢它的外观并希望将其切换为使用ListTile显示它,这是我用来使用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(),
        ),
      ),
    );

You need to use the ListView widget for this.为此,您需要使用ListView小部件。 There is a lot explained in that API reference section, I think you will be able to rework you app after reading. API 参考部分中有很多解释,我认为您将能够在阅读后重新设计您的应用程序。

So you will have a ListView with the children property set to smth like因此,您将拥有一个ListView ,其children属性设置为类似

_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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM