In a function with optional parameters, I want to print all the parameters passed in, not just value but also identifier of each parameter. For example, below is a function with optional named parameters. I print out both arg name and its value using a map instance, that's what I need.
Map temp = new Map();
argumentTest({String a, String b, String c: "DDD"}){
if (a != null) {
temp.addAll({"a":a});
}
if (b != null) {
temp.addAll({"b":b});
}
if (c != null) {
temp.addAll({"c":c});
}
}
void main() {
argumentTest(a:"AAA");
print('$temp'); //{a: AAA, c: DDD}
}
Though ugly, it works. But, is there anything which looks like;
Map temp = new Map();
argumentTest({String a, String b, String c: "DDD"}){
arguments.forEach((arg) => temp.addAll({"arg": arg}));
}
void main() {
argumentTest(a:"AAA");
print('$temp'); //of course, not working.
}
Thank you all and always.
dart:mirrorsbut I have never seen a method to access local variables using mirrors only fields and methods/functions. There is no way to know which parameters where passed. You can only check if a parameter value isnullor the default value you specified but this value could also have been passed by the caller.