Explicit word as function parameter

Viewed 26

I´m learning TypeScript rigth now, and i noticed that you can set a function parameter like this:

function someFunction(color: "red" | "blue" | "green") {
  console.log(color);
}

So, you can just pass only those three strings as a parameter.

Is there anything similar in DART other than ENUMS? i.e. the function parameter is a string but limited to a few words?

1 Answers

You can use an assert:

someFunction(String color) {
  assert(color == "red" || color == "blue" || color == "green");
  print(color);
}
Related