如何在飞镖扑中更新嵌套地图?

时间:2020-09-15 11:43:49

标签: flutter dart

Map<String,dynamic> serviceData = { 
'Hair Service': 
       {'simple hair cut' : 
            { 'price': 100,'duration': 30,},
        },
       {'shampoo + hair cut' : 
            { 'price': 100,'duration': 30,},
        },

//       {'new Service Name' : 
//          { 'price': new price,'duration': new duration,},
//      },

   'Hair styling':
        {'simple' : 
            { 'price': 100,'duration': 30,},
        },
       {'with conditioning' : 
            { 'price': 100,'duration': 30,},
        },
//       {'new Service Name' : 
//          { 'price': new price,'duration': new duration,},
//      },
}

我想在“头发服务”和“发型”中添加/编辑“新服务”

尝试serviceData.update(),但没有成功

1 个答案:

答案 0 :(得分:0)

serviceData["Hair Service"]["new Service Name"] = { 'price': new price,'duration': new duration,};

serviceData["Hair styling"]["new Service Name"] = { 'price': new price,'duration': new duration,};

或同一对象:

serviceData["Hair Service"]["new Service Name"] = { 'price': new price,'duration': new duration,};
serviceData["Hair Styling"]["new Service Name"] = serviceData["Hair Service"]["new Service Name"];