Home > Net >  How to transfer a List into a DataTable rows? Flutter/Dart
How to transfer a List into a DataTable rows? Flutter/Dart

Time:11-15

i have a list and i want to transfer it to my DataTable rows, how can i do that? this list 'cardbills' inside has these values:

print(cardbills);
[{"serial":"281929282881","value":4.8150,"vat":1.1556,"total":5.9706,"energy":0},{"serial":"281929282881","value":1.0567,"vat":0.2536,"total":1.3103,"energy":0}]


DataTable(
                  columns: getColumns(columns),
                  rows: [],
              )

CodePudding user response:

Try this:

DataTable(
   columns: getColumns(columns),
   rows: cardbills.map((e) => DataRow(
                  cells: [
                    DataCell(Text(e['serial'])),
                    DataCell(Text(e['value'])),
                    DataCell(Text(e['vat'])),
                    DataCell(Text(e['total'])),
                    DataCell(Text(e['energy-a'])),
                  ],
                  onSelectChanged: (newValue) {
                    print('row 1 pressed');
                  },
                ))
            .toList(),
)
  • Related