16

What do these square brackets do in the constructor?

Minesweeper([List<String> _input]){
  //...
}

I've checked the Dart's official documentation in the sections "classes" and "lists" but neither seem to have a reference to such a syntax. I guess it's a "direct initializer"(?) so the _input field is filled without writing it explicitly in the constructor?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
aderchox
  • 3,163
  • 2
  • 28
  • 37
  • 4
    These are optional positional parameters. See [here](https://stackoverflow.com/questions/13264230/what-is-the-difference-between-named-and-positional-parameters-in-dart) and [here](https://dart.dev/guides/language/language-tour#optional-parameters). – Reimer Behrends Feb 01 '20 at 06:13

1 Answers1

31

[ ] denotes positional optional parameters { } denotes named optional parameters

See - What is the difference between named and positional parameters in Dart?

Trevor
  • 1,349
  • 10
  • 16
  • 20
    It is not a duplicate question. This question is about square brackets. The other question is not. Someone that does not know that the square brackets mean positional optional parameters (many people) would not be able to find or understand the other question. – Trevor Mar 26 '20 at 17:15