0

In Flutter I Want to dynamic column in my Data Table because from database every time I get different number() of column. how I create Anyone help

1 Answer 1

1

Maybe you can use a StatefulWidget that wraps your DataTable, you can define List<DataColumn> dataColumns; in your state. And every time you get your source data from API/calculations/or somewhere. You can fill this dataColumns list from source data and invoke setState.

Let's say you fetch Column names form database and put it in a List<String> columnNames=['Name','Surname','Phone','Adress'];

setState(() {
   dataColumns=columnNames.map((string)=>DataColumn(label: Text(string)).toList();   
 }); 
    

DataTable(
          columns: dataColumns,
          ////....
    
    )
Sign up to request clarification or add additional context in comments.

4 Comments

" dataColumns " how i create this variable , please one example
because , i get error type '!rows.any((DataRow row) => row.cells.length != columns.length)': is not true.
type 'List<String>' is not a subtype of type 'List<DataColumn>'
Please check answer, I edited to make it more clear.

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.