Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart I';我在使用list.map函数时遇到类型错误_Dart - Fatal编程技术网

Dart I';我在使用list.map函数时遇到类型错误

Dart I';我在使用list.map函数时遇到类型错误,dart,Dart,在DartPad中运行以下代码时出现类型错误 void main() { List<int> list = [10, 20, 30]; List<int> squares = list.map((x) => x * x); squares.forEach((x) => print(x)); } void main(){ 列表=[10,20,30]; 列表方块=List.map((x)=>x*x); 正方形。forEach((x)=>打印(x));

在DartPad中运行以下代码时出现类型错误

void main() {
  List<int> list = [10, 20, 30];
  List<int> squares = list.map((x) => x * x);
  squares.forEach((x) => print(x));
}
void main(){
列表=[10,20,30];
列表方块=List.map((x)=>x*x);
正方形。forEach((x)=>打印(x));
}
获取以下错误

Uncaught exception:
TypeError: Instance of 'MappedListIterable<int, int>': 
type 'MappedListIterable<int, int>' is not a subtype of 
type 'List<int>'
未捕获异常:
TypeError:“MappedListIterable”的实例:
类型“MappedListIterable”不是的子类型
键入“列表”
这里可能有什么问题?

List squares=List.map((x)=>x*x);
List<int> squares = list.map((x) => x * x);
需要

List<int> squares = list.map((x) => x * x).toList();
List squares=List.map((x)=>x*x.toList();
map()
返回一个
Iterable
,而不是
列表