首页 > 解决方案 > 如何在飞镖中调用采用 Map 类型参数的函数?

问题描述

我想知道 Map 的执行情况。

void main(){
  var info = userInfo(); /* what can I pass here as args? */
  print(info);
}

userInfo(Map user){
  /* what do I write here? */
}

标签: flutterdart

解决方案


您好,您可以通过地图并使用地图如下

  void main(){
     Map user_map= 
     {
    "first_name" : "fname",
    "last_name" : "lname",
    "gender" : "male",
    "location" : 
          { "state" : "state",
            "country" : "country",
            "place" : "place"
           } 
    }    
        
    var info = userInfo(user_map); /* what can I pass here as args? */
    print(info);
    }
            
            userInfo(Map user){
              /* here you can use the map values like if you want to print the value of key 
              first_name */
             print(user["first_name"]);
    
            }

推荐阅读