方法 map() 不适用于地图中的列表

Method map() dose not work for a List in a Map

我有这样一张地图:

Map userInfo={
     'name':'jack',
     'age':30,
     'interests':[
       {'name':'swimming','level':1},{'name':'running','level':2},
     ]
    }

现在我想使用方法 map() 将兴趣转换为 Widget 列表,如果我使用下面的 userInfo['interests'],它将不起作用:

userInfo['interests'].map((item){return new Text(item['name'])}).toList() //not work

但是,如果先将 userInfo['interests'] 保存在一个变量中,它会起作用:

List tmpVariable=userInfo['inetrests'];
tmpVariable.map((item){return new Text(item['name'])}).toList()  //this works

所以问题是,如果我得到了上面这样的结构,我可以直接映射它吗?或者最好的处理方法是什么?我认为使用变量不太好。 :)

试试这个:

(userInfo['interests'] as List).map((item){return new Text(item['name'])}).toList()