Functions: Optional Positional Parameters


Wrapping the option in square brackets will make it optional. Its value will be null.

examples/dart-intro/prompt.dart
String prompt(String text, [int count]) {
  if (count == null) {
    count = 1;
  }
  for (int i = 0; i < count; i++) {
    print(text);
  }
}

void main() {
    prompt("Your name:", 3);
    prompt("Your Cat:");
}