Dart how to make a function that can accept any number of args

dart

Solution

There is no real vararg support in Dart. There was, but it has been removed. As Fox32 said, you can do this with `noSuchMethod`. But, if there is no real need to call the method like `method(param1, param2, param3)`, you could just skip this step and define a `Map` or `List` as parameter. Dart supports literals for both types, so the syntax is also short and clear:

void method1(List params) {
  params.forEach((value) => print(value));
}

void method2(Map params) {
  params.forEach((key, value) => print("$key -- $value"));
}

void main() {
  method1(["hello", "world", 123]);
  method2({"name":"John","someNumber":4711});
}

Problem

Coming from `python`, i know i can easily accomplish that : ``` def someFunc(*args): for i in args: print i ``` That way i can give 100 args with ease. How to do something like that on Dart ? Thx.

Original source

Related problems