0

In my code I want that the user can add a new DataCell to a DataRow in my DataTable. But I dont know how I can add a single DataCell. My Code looks like this, but it didnt work:

  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')))
  }

1 Answer 1

0

You will need set a new state with RowList.add(DataCell(Text('Column 4'))).

So you should habe a stateful widget and then, when calling _addDataCell() via some button, there should be an onPressed: setState(() {_addDataCell();}) (pseudo code, check syntax, since I just started again with Flutter)

Sign up to request clarification or add additional context in comments.

3 Comments

yes i have a stateful widget and a button to call the _addDataCell, this is only a snippet from my Code. My Problem is, that i want to add a single cell to a DataRow and the code 'RowList.add(DataCell(Text('Column 4')))' dont work.
hard to tell not seeing the rest of the relevant code. But as I said, make sure that due set a new state. Otherwise the widget will not rebuild and hence you would not see any new cell.
thank you. My only problem is that i need to know how to insert a new cell to a DataRow, the rest works pretty fine. Is there a function like 'RowList.cells.add(DataCell(Text('Column 4')))' so that the Text 'Column 4' gets added in the DataRow? So the result looks like [Column1; Column2; Column3; Column4]?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.