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: [...]
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, 2022Comments
-
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.
-
Naveen Avidi about 4 yearsThis may help you ! stackoverflow.com/a/59783496/5557479
-
-
Raine Dale Holgado about 4 yearsThanks, but what im trying to do is routing it to another page and sending the index value of that row.
-
Jimmy over 3 yearsThis doesn't work since the property
rows
ofDataTable
expects aList<DataRow>
so you can't assign aList<GestureDetector>
to it. -
Codered about 3 yearsWhat I ended up doing was just have the same callback for every cell in the row.