From the Dart language tour you can do this:
class Person {
final _name;
const Person(this._name);
}
How can I get a named parameter like this:
class Person {
final _name;
const Person({@required this._name});
}
So the usage will be:
const Person(name: 'SD')
I still want a const
constructor. Is this possible?
You can, but not with the this.variable
syntax
const Person({ String name}) : _name = name;
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