简体   繁体   English

如何在 dart 中调用采用 Map 类型参数的 function?

[英]How to call a function which takes parameter of type Map in dart?

I want to know the execution in case of Map.我想知道 Map 的执行情况。

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

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

hi there you can pass a map and use the map as follow您好,您可以通过 map 并使用 map 如下

  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"]);
    
            }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 dart 中将默认参数分配给除 map 参数之外的函数 - How to assign a default parameter to a function aside of map parameter in dart 如何使地图值成为 dart 函数参数中的常量 - How do I make the map value a constant in function parameter in dart 有没有办法在 dart 中定义一个接受索引参数的 getter? - Is there a way to define a getter in dart which takes an index parameter? Dart:如何将function作为参数传递 - Dart: How to pass function as parameter 如何创建一个指向 dart function 的指针,它在 dart:ffi 中接受一个字符串? - How to create a pointer to a dart function that takes a String in dart:ffi? Dart 中 Function 类型的参数默认值 - Default value for parameter of Function type in Dart function 作为参数,在 dart 中具有泛型 object 返回类型 - function as parameter with generic object return type in dart 如何获取某些值的值作为类型<string>哪个在 Dart/Flutter 的列表中的 Map 内?</string> - how to get values of some values as type<String> which is inside a Map inside List in Dart/Flutter? Dart - 添加多个参数类型:Map<string, dynamic></string,> - Dart - Adding more than one parameter Type: Map<String, dynamic> 如何修复错误:无法将参数类型“Function”分配给参数类型“void Function()?”。 -“功能”来自“dart:core” - how to fix Error: The argument type 'Function' can't be assigned to the parameter type 'void Function()?'. - 'Function' is from 'dart:core'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM