gpt4 book ai didi

arrays - Flutter - 在同一指令中创建列表和 'addAll'

转载 作者:IT王子 更新时间:2023-10-29 07:18:58 25 4
gpt4 key购买 nike

我正在尝试搜索数组中的元素。当得到它时,我需要在数组末尾附加一些元素。

我试过类似的。

List dataModelo = allMakers //THIS IS THE MAIN ARRRAY
.where((modelo) =>
modelo["fabricante"] ==
fabricante["fabricante"])
.toList()
.addAll([
{
"id": 0,
"fabricante":
'Test,
"modelo":
'Test'
}
]);

但是返回

The expression here has a type of 'void', and therefore cannot be used.

所以有人知道我该怎么做吗?

解决方案:

 dataModelo = allMakers
.where((modelo) =>
modelo["fabricante"] ==
fabricante["fabricante"])
.followedBy([
{
"id": 0,
"fabricante":
'TEXT',
"modelo":
'TEXT'
}
]).toList();

最佳答案

使用cascade notation.where(/**/).toList() 部分之后。

例如

final arr = [1, 2, 3];
print(arr.where((a) => a > 2).toList()
..addAll([ 4, 5 ])); // returns [3, 4, 5]

换句话说,将另一个 . 添加到您的 .addAll 部分应该可以解决问题。

关于arrays - Flutter - 在同一指令中创建列表和 'addAll',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56393380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com