我有一个需要编辑数量的数据表。我正在检测下面的代码选择了哪一行,效果很好,但我想隐藏CheckBox Column
关于不保留复选框列如何保持当前行为的任何建议?
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Sample",
style: TextStyle(color: Colors.white),
),
body: Column(children: <Widget>[
DataTable(
sortAscending: true,
columns: <DataColumn>[
DataColumn(
label: Text('Product name'),
),
DataColumn(
label: Text('Product Quantity'),
),
],
rows: items
.map(
(itemRow) => DataRow(
onSelectChanged: (bool selected) {
if (selected) {
//'row-selected: ${itemRow.index}'
}
},
cells: [
DataCell(
Text(itemRow.itemName),
showEditIcon: false,
placeholder: false,
),
DataCell(
Text(itemRow.itemQuantity),
showEditIcon: true,
placeholder: false,
//onTap: _getSelectedRowInfo,
),
],
),
)
.toList(),
)
]),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
));
}
}
您只需要向DataTable
添加一个属性,即showCheckboxColumn
为假。
您编辑后的完整代码将为
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Sample",
style: TextStyle(color: Colors.white),
),
body: Column(children: <Widget>[
DataTable(
showCheckboxColumn: false,
sortAscending: true,
columns: <DataColumn>[
DataColumn(
label: Text('Product name'),
),
DataColumn(
label: Text('Product Quantity'),
),
],
rows: items
.map(
(itemRow) => DataRow(
onSelectChanged: (bool selected) {
if (selected) {
//'row-selected: ${itemRow.index}'
}
},
cells: [
DataCell(
Text(itemRow.itemName),
showEditIcon: false,
placeholder: false,
),
DataCell(
Text(itemRow.itemQuantity),
showEditIcon: true,
placeholder: false,
//onTap: _getSelectedRowInfo,
),
],
),
)
.toList(),
)
]),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
));
}
}