This makes the argument a named optional argument.
When you create an instance Personyou can
Person p;
p = new Person(); // default is _newDbConnection
p = new Person(connectionFactory: aConnectionFactoryInstance);
- no
{}argument will be required - with
[]argument will be an optional positional argument
// Constructor with positional optional argument
Person([this.connectionFactory = _newDBconnection]);
...
Person p;
p = new Person(); // same as above
p = new Person(aConnectionFactoryInstance); // you don't specify the parameter name
Named optional parameters are very convenient for logical arguments (but, of course, for other cases).
p = new Person(isAlive: true, isAdult: false, hasCar: false);
, :
- () ( )
- () ( )
, . : =. , Map ( ).
= Dart 2 , : .
: