首页 > 解决方案 > Flutter:动态地将值添加到复杂的地图中

问题描述

在地图中

Map test = {};

从 textFields onChanged 事件添加值的方法是什么:

onChanged: (value) {  
    // This is the onChanged Method of quantity textField            
    test['$index'] = ? /* This is the V/K 'qty': value */
},

我还有两个 texFields:

onChanged: (value) {  
        // This is the onChanged Method of element1 textField            
        test['$index'] = ? /* This is theV/K 'el1': value */
    },

和:

onChanged: (value) {  
            // This is the onChanged Method of element2 textField           
            test['$index'] = ? /* This is theV/K 'el2': value */
        },

这是最终的愿望地图:

{
    0: {qty: 100, el1: element1, el2: element2}, 
    1: {qty: 200, el1: element1, el2: element2}, 
    2: {qty: 300, el1: element1, el2: element2}
}

其中 0,1,2...N 是索引

我将永远感谢任何帮助或建议

标签: flutterdart

解决方案


推荐阅读