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
Dictionary 达特赢得';由于类型不匹配,无法编译&x27;列表<;T>';can';不能分配给参数类型';列表<;T>;函数()';_Dictionary_Dart - Fatal编程技术网

Dictionary 达特赢得';由于类型不匹配,无法编译&x27;列表<;T>';can';不能分配给参数类型';列表<;T>;函数()';

Dictionary 达特赢得';由于类型不匹配,无法编译&x27;列表<;T>';can';不能分配给参数类型';列表<;T>;函数()';,dictionary,dart,Dictionary,Dart,代码的相关部分如下所示: static final Map\u availableProviders={}; 提供程序(this.name、this.\u requiresKey、this.\u版本){ _versions.forEach((版本)=>{ Provider.\u可用的Providers.putIfAbsent(版本,[]), Provider.\u可用Providers[版本]。添加(此) }); } _版本是一组字符串,当我尝试运行时,收到以下错误: lib/src/api/

代码的相关部分如下所示:

static final Map\u availableProviders={};
提供程序(this.name、this.\u requiresKey、this.\u版本){
_versions.forEach((版本)=>{
Provider.\u可用的Providers.putIfAbsent(版本,[]),
Provider.\u可用Providers[版本]。添加(此)
});
}
_版本是一组字符串,当我尝试运行时,收到以下错误:

lib/src/api/Provider.dart:18:71: Error: The argument type 'List<Provider>' can't be assigned to the parameter type 'List<Provider> Function()'.
 - 'List' is from 'dart:core'.
 - 'Provider' is from 'package:bible/src/api/Provider.dart' ('lib/src/api/Provider.dart').
          Provider._availableProviders.putIfAbsent(version, <Provider>[]),
lib/src/api/Provider.dart:18:71:错误:无法将参数类型“List”分配给参数类型“List Function()”。
-“列表”来自“dart:core”。
-“Provider”来自“package:bible/src/api/Provider.dart”(“lib/src/api/Provider.dart”)。
Provider.\u可用的Providers.putIfAbsent(版本,[]),
无法将参数类型“List”分配给参数类型“List Function()”


我不确定这个错误是否与我创建的空列表的符号有关,或者与我如何实例化映射有关。任何帮助都将不胜感激

映射的putIfAbsent的第二个参数是函数,它返回要放入的值,而不是值本身:

将代码重写为以下内容:

static final Map\u availableProviders={};
提供程序(this.name、this.\u requiresKey、this.\u版本){
_versions.forEach((版本)=>{
Provider.\u availableProviders.putIfAbsent(版本,()=>[]),可供选择,
Provider.\u可用Providers[版本]。添加(此)
});
}

你能分享
putIfAbsent
?啊,这是一个“阅读该死的手册”的案例哈哈。非常感谢。