I have a DataTable
that I want to make dynamic based on the user's date selection. The number of columns will therefore differ.
My current code creates a List<Map>
from a Firestore collection for the headers and another for the Row/Cell values. When comparing the length of both the headers and cell content, they are the same size.
My current code to create the table:
// Just providing more detail about the variables used
List<DataColumn> dataColumns = [];
List<DataCell> dataRows = [];
dataColumns = newDateRange.map((string) =>
DataColumn(label: Text(string))).toList();
dataRows = listOfRows.map((cell) => DataCell(Text(cell.toString()))).toList();
// DataTable creation
DataTable(
columnSpacing: dataTableColumnSpacing,
border: dataTableBorder,
decoration: dataTableBoxDecoration,
columns: dataColumns,
rows: [DataRow(cells: dataRows)],
)
From what I have tested, the column headers work as intended, so there is something wrong with the rows section - either variable declaration, map section or in the rows section in the DataTable creation.
The error that I am getting is that the row length is not equal to the column length.
Any help and/or guidance will be appreciated.