today i was wondering if there is a way to handle the double click event in each row of a DataTable.
Does anyone knows?
EDIT: I tried by wrapping all the DataTable
with InkWell
but by doing this I wont be able to access the index/content of each row. This i s the code
DataTable(
onSelectAll: (val) {
setState(() {
selectedIndex = -1;
});
},
border: TableBorder.all(color: textColor),
columnSpacing: 20,
showCheckboxColumn: false,
headingRowHeight: 32,
headingRowColor: MaterialStateColor.resolveWith((states) => mainColor),
dataRowMinHeight: 40,
dataRowMaxHeight: 40,
columns: const <DataColumn>[
DataColumn(label: Text("Cognome", style: TextStyle(color: Colors.white),)),
DataColumn(label: Text("Nome", style: TextStyle(color: Colors.white),)),
DataColumn(label: Text("Email", style: TextStyle(color: Colors.white),)),
DataColumn(label: Text("Telefono", style: TextStyle(color: Colors.white),)),
DataColumn(label: Text("Ore/Sett", style: TextStyle(color: Colors.white))),
DataColumn(label: Text("Disp./Sett", style: TextStyle(color: Colors.white))),
],
rows: List<DataRow>.generate(
snapshot.data!.length, (index) {
return DataRow(
color: MaterialStateProperty.resolveWith((states) {
if(states.contains(MaterialState.selected)) {
return accentColor50;
}
if(index % 2 == 0) {
return mainColor200;
}
return null;
}),
selected: index == selectedIndex,
onSelectChanged: (value) {
setState(() {
selectedIndex = index;
});
context.read<GestioneDocentiProvider>().setSelectedRow(index);
context.read<GestioneDocentiProvider>().setDocenteSelezionato(snapshot.data![index]);
context.read<GestioneOrarioCompletoProvider>().setDocenteSelezionato(snapshot.data![index]);
context.read<GestioneDocentiProvider>().impostaSelezioneRiga();
context.read<GestioneOrarioCompletoProvider>().impostaOrario();
},
cells: <DataCell>[
DataCell(GestureDetector(child: Text(snapshot.data![index].cognome))),
DataCell(Text(snapshot.data![index].nome)),
DataCell(Text(snapshot.data![index].email)),
DataCell(Text(snapshot.data![index].telefono)),
DataCell(Align(
alignment: Alignment.center,
child: Text(
snapshot.data![index].oreSettimanali,
style: snapshot.data![index].oreSettimanali == "0"
? TextStyle(color: Colors.red[400], fontWeight: FontWeight.bold)
: const TextStyle(color: textColor)))),
DataCell(Align(
alignment: Alignment.center,
child: Text(
snapshot.data![index].oreDoc,
style: snapshot.data![index].oreDoc == "0"
? TextStyle(color: Colors.red[400], fontWeight: FontWeight.bold)
: const TextStyle(color: textColor))))
],
);
})),
wrap the widget with InkWell and there is a property named onDoubleTap with this you can achieve it like bellow