Couldn't map data to datarow cell, data table widget flutter

289 views Asked by At

I'm creating a datawidgetto display some data in table, The data content is in a list, I tried mapping it to rows of datawidget but I get this error when I try amountpaid.map

The argument type 'Iterable' can't be assigned to the parameter type 'List'

I don't understand the error, what does that mean and how do I solve it.

amountpaidclass

class amountPaidClass {
  int amount;
  amountPaidClass({required this.amount});
}

var amountpaid = <amountPaidClass>[
  amountPaidClass(amount: 1000),
  amountPaidClass(amount: 5000),
  amountPaidClass(amount: 7000)
];

Displaying data

          body: Center(
            child: Container(
              child: DataTable(
                  columns: const [DataColumn(label: Text('Amount'))],
                  rows: amountpaid.map((amountPaidClass) => null)
                  ),
            ),
          )
1

There are 1 answers

0
Jon Mountjoy On BEST ANSWER

Check out the type of List.map. It produces an Iterable. So if you want a List again, you'll have to do something - in this case, calling .toList() on your Iterable should do it.

In other words, amountpaid.map( ... ).toList().

Using a good code editor should show you the type of map in a hover, which should make this analysis easier.

(As an aside, your code still looks buggy, as you'll be producing a list of. nulls, as you map each item to a null.)