【问题标题】:Flutter display sql data in ListTile instead of DataCellFlutter 在 ListTile 中显示 sql 数据而不是 DataCell
【发布时间】:2020-07-21 16:24:23
【问题描述】:

我正在使用 DataCell 显示从我的 sql 数据库中获取的数据列表,但我不太喜欢它的外观并希望将其切换为使用 ListTile 显示它,这就是我的代码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(),
        ),
      ),
    );

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

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

    因此,您将拥有一个 ListView 并将 childrenproperty 设置为类似

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

    【讨论】:

    • 好的,谢谢。我要读它。但是你知道我将如何使用_chatUsers.map((user))吗?
    • 谢谢,我试试看。
    猜你喜欢
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多