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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.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
Flutter 错误不能';t推断类型参数';T';。使用Map.fromIterable时_Flutter_Dart - Fatal编程技术网

Flutter 错误不能';t推断类型参数';T';。使用Map.fromIterable时

Flutter 错误不能';t推断类型参数';T';。使用Map.fromIterable时,flutter,dart,Flutter,Dart,我正在尝试将列表转换为映射,用于CupertinoSlidingSegmentedControl的子级。我尝试使用Map.fromIterable但是我得到了一个错误 这是我的密码: final List tabValues=['first','second','third']; Cupertinoslidings分段控制( groupValue:selectedTab, onValueChanged:\u onTabChange, 儿童:Map.fromIterable( tabValues,

我正在尝试将
列表
转换为
映射
,用于
CupertinoSlidingSegmentedControl
的子级。我尝试使用
Map.fromIterable
但是我得到了一个错误

这是我的密码:

final List tabValues=['first','second','third'];
Cupertinoslidings分段控制(
groupValue:selectedTab,
onValueChanged:\u onTabChange,
儿童:Map.fromIterable(
tabValues,
值:(元素)=>\选项卡内容(元素),
),
)
小部件选项卡内容(字符串文本){
返回文本(Text);
}
获取错误:

无法推断类型参数“t”

该函数需要
映射函数

您需要同时提供这两个函数或不提供,如果选择后者,这意味着您将得到一个
映射
,其中键和值函数将替换为标识函数


在你的情况下,我会这样做:

children:tabValues.asMap().map((索引,tabValue)=>MapEntry(索引,tabContent(tabValue)))

应该是小部件的索引,它是在我们执行
tabValues.asMap()
时创建的,因此现在我们只需要调用
.map
tabValue
转换为小部件。

您缺少
mapping@smac89你能给我看一个样品吗?在你的
地图中,
int
应该是小部件的索引吗?@smack89是。所以结果应该是
{0:Text('first),1:Text('second'),2:Text('third)}