How do I combine three lists in Flutter/Dart?

Viewed 275

I want to combine three lists, my lists:

var px = [0.1, 0.2, 0.3];
var x = [0, 1, 2];
var mutiply = [0, 0.2, 0.6];

How can I combine these three lists? I want to retrieve all the list data into a table with ListView.

I want to represent the data like this:

Example Image Attached for Final input

Please guide me how to do it! Thank You!

1 Answers

You can use DataTable for this case.

enter image description here

You can config others properties.

 DataTable(
            headingRowColor:
                MaterialStateProperty.all(Colors.blueGrey.withOpacity(.5)),
            showBottomBorder: true,
            columns: const [
              DataColumn(
                label: Text("x"),
              ),
              DataColumn(
                label: Text("p(x)"),
              ),
              DataColumn(
                label: Text("x*p(x)"),
              ),
            ],
            rows: [
              DataRow(cells: [
                DataCell(Text(x[0].toString())),
                DataCell(Text(px[0].toString())),
                DataCell(Text(mutiply[0].toStringAsFixed(3))),
              ]),
              DataRow(cells: [
                DataCell(Text(x[1].toString())),
                DataCell(Text(px[1].toString())),
                DataCell(Text(mutiply[1].toStringAsFixed(3))),
              ]),
              DataRow(cells: [
                DataCell(Text(x[2].toString())),
                DataCell(Text(px[2].toString())),
                DataCell(Text(mutiply[2].toStringAsFixed(3))),
              ]),
            ],
          ),
    
Related