繁体   English   中英

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

[英]Flutter display sql data in ListTile instead of 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(),
        ),
      ),
    );

为此,您需要使用ListView小部件。 API 参考部分中有很多解释,我认为您将能够在阅读后重新设计您的应用程序。

因此,您将拥有一个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