简体   繁体   中英

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 :

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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