I would like to make a datacolumn clickable, such that when the user clicks on it, an overlay opens up. I’ve tried to add a IconButton, but i doesn’t work. Does anyone has an idea how to do that properly in flutter?
Code:
SizedBox(
height: 500,
width: double.infinity,
child: DataTable2(
minWidth: 600,
columnSpacing: defaultPadding,
columns: const [
DataColumn(
IconButton( <------------- This doesn't work
icon: Icons.abs,
onPressed: () {},
),
label: Text("Car ID"),
),
DataColumn(label: Text("Date")),
DataColumn(label: Text("Avg. Speed")),
DataColumn(label: Text("Video File")),
],
rows: List.generate(demoRecentFiles.length,
(index) => recentFileDataRow(demoRecentFiles[index])),
)),
2
Answers
To make data column clickable, just wrap your label with GestureDetector() widget.
label
attribute ofDataColumn
as well as positional parameter ofDataCell
inDataRow
can be any widget. So feel free to use any clickable widget there. Here’s working snippet withIconButton
like you wanted it to be. You can try it in Dartpad.