This commit is contained in:
Hillel Coren 2020-02-14 16:28:50 +02:00
parent 8d7c68219a
commit 7bc64b1db4
1 changed files with 35 additions and 1 deletions

View File

@ -279,7 +279,7 @@ class _ReportDataTableState extends State<ReportDataTable> {
children: <Widget>[
DataTable(
columns: reportResult.totalColumns(context),
rows: [],
rows: reportResult.totalRows(context),
),
],
),
@ -718,6 +718,40 @@ class ReportResult {
)
];
}
List<DataRow> totalRows(BuildContext context) {
final rows = <DataRow>[];
final Map<String, Map<String, double>> totals = {};
for (var i = 0; i < data.length; i++) {
final row = data[i];
final cells = <DataCell>[
DataCell(Text('')),
DataCell(Text('')),
];
for (var j = 0; j < row.length; j++) {
final cell = row[j];
final column = columns[j];
if (getReportColumnType(column) == ReportColumnType.number) {
cells.add(DataCell(cell.renderWidget(context, column)));
final String currencyId = (cell as ReportNumberValue).currencyId;
if (!totals.containsKey(currencyId)) {
totals[currencyId] = {'count': 0};
}
if (!totals[currencyId].containsKey(column)) {
totals[currencyId][column] = 0;
}
totals[currencyId][column] += cell.value;
}
}
rows.add(DataRow(cells: cells));
}
print('## TOTALS: $totals');
return rows;
}
}
abstract class ReportElement {