Flutter DataTable -Tap on entire Row

2,085

Had the same issue, realised you could use the onSelectChanged from the DataRow.

Example from the DataTable

rows: searchList.map((item) {
        return DataRow(
          onSelectChanged: (bool value) {
             // ENTER CALLBACK HERE (It's not restricted to use the bool)
          },
          cells: ...

Note, this will make the Checkbox visible, if you do not require this then make sure you force the showCheckboxColumn to false in the DataTable:

    return DataTable(
      showCheckboxColumn: false,
      columns: [...]
Share:
2,085
Raine Dale Holgado
Author by

Raine Dale Holgado

BS in Computer Engineering, graduated from Silliman University. Interested in Web/Mobile development and Dart/Flutter. Love to explore new technology.

Updated on December 17, 2022

Comments

  • Raine Dale Holgado
    Raine Dale Holgado over 1 year

    im new to Flutter. I need help on OnTap in DataCell. For example, instead of tapping one cell, I want the Row.

    Heres my codes

    DataTable(
         columns: <DataColumn>[
            DataColumn(
              label: Text("Title"),
              ),
            DataColumn(
              label: Text("Contacts"),
              ),
             )
            ],
             rows: contracts.map((contract) => DataRow(
                 cells: [
                   DataCell(Text(contract.title),
                      onTap: () {
                          Navigator.push(context, MaterialPageRoute(
                                  builder: (context) => List(),),
                               );
                             }),
                   DataCell(Text(contract.contacts),
                      onTap: () {
                          Navigator.push(context, MaterialPageRoute(
                                  builder: (context) => List(),),
                               );
                             }),).toList()
    

    i want to click on a specific row and it will route to another page also sends the index value of it.

  • Raine Dale Holgado
    Raine Dale Holgado about 4 years
    Thanks, but what im trying to do is routing it to another page and sending the index value of that row.
  • Jimmy
    Jimmy over 3 years
    This doesn't work since the property rows of DataTable expects a List<DataRow> so you can't assign a List<GestureDetector> to it.
  • Codered
    Codered about 3 years
    What I ended up doing was just have the same callback for every cell in the row.