Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Named parameter with underscore in Dart class

Tags:

flutter

dart

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?

like image 559
S.D. Avatar asked Jan 06 '19 09:01

S.D.


1 Answers

You can, but not with the this.variable syntax

const Person({ String name}) : _name = name;
like image 186
Rémi Rousselet Avatar answered Dec 26 '22 16:12

Rémi Rousselet