Flutter 如何在颤振中找到两个贴图中的匹配值?

Flutter 如何在颤振中找到两个贴图中的匹配值?,flutter,dart,Flutter,Dart,我试图在《颤栗》中的两个不同地图(游戏-浮动物品)中找到匹配的“关卡”。如何找到这些项并创建一个键为“level”且值与浮动项匹配的新映射?下面是示例代码 List <Game> games = [ { "id": "Level 1", "level": 1, }, { "id": "Level 2", "

我试图在《颤栗》中的两个不同地图(游戏-浮动物品)中找到匹配的“关卡”。如何找到这些项并创建一个键为“level”且值与浮动项匹配的新映射?下面是示例代码

List <Game> games = [
    {
      "id": "Level 1",
      "level": 1,
    },
    {
      "id": "Level 2",
      "level": 2,
    },
    {
      "id": "Level 3",
      "level": 3,
    },
   ];


List <FloatingItem> floatingItems = [
    {
      "level": "1",
      "position": 0
    },
    {
      "level": "1",
      "position": 5
    },
    {
      "level": "3",
      "position": -5
    },
    {
      "level": "3",
       "position": 0
    },
    {
      "level": "2",
      "position": 5
    },
    {
      "level": "3",
      "position": -5
    },
   ];
列出游戏=[
{
“id”:“1级”,
"一级",,
},
{
“id”:“2级”,
“级别”:2,
},
{
“id”:“3级”,
"三级",,
},
];
列表浮动项=[
{
“级别”:“1”,
“位置”:0
},
{
“级别”:“1”,
“职位”:5
},
{
“级别”:“3”,
“职位”:-5
},
{
“级别”:“3”,
“位置”:0
},
{
“级别”:“2”,
“职位”:5
},
{
“级别”:“3”,
“职位”:-5
},
];

假设您有这两个列表。我更改了类型,因为我不知道类
Game
FloatingItem
是什么样子

final List <Map<String, dynamic>> games = [
    {
      "id": "Level 1",
      "level": 1,
    },
    {
      "id": "Level 2",
      "level": 2,
    },
    {
      "id": "Level 3",
      "level": 3,
    },
];

final List <Map<String, dynamic>> floatingItems = [
    {
      "level": 1,
      "position": 0
    },
    {
      "level": 1,
      "position": 5
    },
    {
      "level": 3,
      "position": -5
    },
    {
      "level": 3,
       "position": 0
    },
    {
      "level": 2,
      "position": 5
    },
    {
      "level": 3,
      "position": -5
    },
];
输出

(
  {
    level: 1, 
    floatingItems: ({level: 1, position: 0}, {level: 1, position: 5})
  },
  {
    level: 2,
    floatingItems: ({level: 2, position: 5})
  }, 
  {
    level: 3,
    floatingItems: ({level: 3, position: -5}, {level: 3, position: 0},
                    {level: 3, position: -5})
  }
)

一定有更好的方法,但For循环可以很容易地工作。
(
  {
    level: 1, 
    floatingItems: ({level: 1, position: 0}, {level: 1, position: 5})
  },
  {
    level: 2,
    floatingItems: ({level: 2, position: 5})
  }, 
  {
    level: 3,
    floatingItems: ({level: 3, position: -5}, {level: 3, position: 0},
                    {level: 3, position: -5})
  }
)