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?
It is a , -separated list of expressions that can access constructor parameters and can assign to instance fields, even final instance fields. This is handy to initialize final fields with calculated values.
An initializer list allows you to assign properties to a new instance variables before the constructor body runs, but after creation. This is handy when you want to set a final variables value, but the value isn't a compile-time constant.
Dart defines a constructor with the same name as that of the class. A constructor is a function and hence can be parameterized. However, unlike a function, constructors cannot have a return type. If you don't declare a constructor, a default no-argument constructor is provided for you.
A factory constructor is a constructor that can be used when you don't necessarily want a constructor to create a new instance of your class. This might be useful if you hold instances of your class in memory and don't want to create a new one each time (or if the operation of creating an instance is costly).
[ ] denotes positional optional parameters { } denotes named optional parameters
See - What is the difference between named and positional parameters in Dart?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With