首页 > 解决方案 > 错误:“列表”类型的值' 不能分配给 'List 类型的变量'

问题描述

我有 list temp 并调用函数 List 但发生此错误

此错误仅在更新颤振后发生

A value of type 'List<dynamic>' can't be assigned to a variable of type 'List<int>'.

我想虽然没有 List ,,,

我怎样才能解决这个问题 ??

 List<int> arr = [];
 List<List<int>> temp = [
    [3,4],
    [3,5],
    [4,3],
    [4,4],
    [5,2],
    [5,5],
    [2,3],
    [2,4],
 ];
 arr = chord3(0,temp[2]); // I call chord3 function here


 List chord3(f,List<int> s){ // this is function and error occurs here
    List<int> temp = [];
    temp.add(f);
    temp.add(1);
    return temp;
 }

标签: flutterdart

解决方案


只需在int此处添加:

List<int>chord3(f,List<int> s){ // this is function and error occurs here
    List<int> temp = [];
    temp.add(f);
    temp.add(1);
    return temp;
 }

你也有这个选项,同样的结果:

 arr = List<int>.from(chord3(0,temp[2])); 

推荐阅读