I'm creating a datawidget
to 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<Null>' can't be assigned to the parameter type 'List<DataRow>'.
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('Ammount'))],
rows: amountpaid.map((amountPaidClass) => null)
),
),
)
CodePudding user response:
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.)