![](/img/trans.png)
[英]How to add column widget inside a flutter DataTable DataCell?
[英]How to add a DataCell to a DataRow?
在我的代碼中,我希望用戶可以將新的 DataCell 添加到我的 DataTable 中的 DataRow。 但我不知道如何添加單個 DataCell。 我的代碼看起來像這樣,但它不起作用:
List<DataRow> RowList = [
DataRow(cells: <DataCell>[
DataCell(Text('Column 1')),
DataCell(Text('Column 2')),
DataCell(Text('Column 3')),
]),
];
void _addDataCell() {
RowList.add(DataCell(Text('Column 4')))
}
您需要使用RowList.add(DataCell(Text('Column 4')))
設置一個新狀態。
所以你應該是一個有狀態的小部件,然后,當通過某個按鈕調用_addDataCell()
,應該有一個onPressed: setState(() {_addDataCell();})
(偽代碼,檢查語法,因為我剛開始使用 Flutter )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.