无法将数据映射到数据行单元格,数据 table 小部件抖动
Couldn't map data to datarow cell, data table widget flutter
我正在创建一个 datawidget
来显示 table 中的一些数据,数据内容在一个列表中,我尝试将它映射到 datawidget
的行,但我明白了当我尝试 amountpaid.map
时出错
The argument type 'Iterable' can't be assigned to the parameter type 'List'
我不明白这个错误,这是什么意思,我该如何解决。
付费类金额
class amountPaidClass {
int amount;
amountPaidClass({required this.amount});
}
var amountpaid = <amountPaidClass>[
amountPaidClass(amount: 1000),
amountPaidClass(amount: 5000),
amountPaidClass(amount: 7000)
];
显示数据
body: Center(
child: Container(
child: DataTable(
columns: const [DataColumn(label: Text('Amount'))],
rows: amountpaid.map((amountPaidClass) => null)
),
),
)
Check out the type of List.map。它产生一个 Iterable
。因此,如果您再次想要 List
,则必须做一些事情 - 在这种情况下,在 Iterable
上调用 .toList()
应该可以做到。
换句话说,amountpaid.map( ... ).toList()
。
使用好的代码编辑器应该会在悬停时向您显示 map
的类型,这应该会使分析更容易。
(顺便说一句,您的代码看起来仍然有问题,因为您将生成一个 .null 列表,因为您将每个项目映射到 null。)
我正在创建一个 datawidget
来显示 table 中的一些数据,数据内容在一个列表中,我尝试将它映射到 datawidget
的行,但我明白了当我尝试 amountpaid.map
The argument type 'Iterable' can't be assigned to the parameter type 'List'
我不明白这个错误,这是什么意思,我该如何解决。
付费类金额
class amountPaidClass {
int amount;
amountPaidClass({required this.amount});
}
var amountpaid = <amountPaidClass>[
amountPaidClass(amount: 1000),
amountPaidClass(amount: 5000),
amountPaidClass(amount: 7000)
];
显示数据
body: Center(
child: Container(
child: DataTable(
columns: const [DataColumn(label: Text('Amount'))],
rows: amountpaid.map((amountPaidClass) => null)
),
),
)
Check out the type of List.map。它产生一个 Iterable
。因此,如果您再次想要 List
,则必须做一些事情 - 在这种情况下,在 Iterable
上调用 .toList()
应该可以做到。
换句话说,amountpaid.map( ... ).toList()
。
使用好的代码编辑器应该会在悬停时向您显示 map
的类型,这应该会使分析更容易。
(顺便说一句,您的代码看起来仍然有问题,因为您将生成一个 .null 列表,因为您将每个项目映射到 null。)