1

Why does this work:

class Person extends StatelessWidget { 
  final String name;

  Person({ this.name });

  ...
}

but the following gives an error ('_name' can't be used as a setter because it is final. Try finding a different setter, or making name' non-final.):

class Person extends StatelessWidget { 
  final String _name;

  Person({ name }) {
    this._name = name;
  }

  ...
}

Is this: ({ this.name }) doing something different under the hood?

Colin Ricardo
  • 16,488
  • 11
  • 47
  • 80
  • I am aware that the two questions are not completely identical, but I have answered your question in the linked answer and you can even learn about what the initializer list is. – creativecreatorormaybenot Feb 06 '20 at 13:54

0 Answers0