Flutter在ListTile中显示sql数据而不是DataCell [英] Flutter display sql data in ListTile instead of DataCell

查看:52
本文介绍了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(),
        ),
      ),
    );

推荐答案

您需要使用

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 childrenproperty 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆