In Dart, as discussed when we covered packages, the privacy is at the library level, but it is still possible to have private fields in a class even though Dart does not have the keywords public, protected, and private. A simple return of a private field's value can be performed with a one-line function:
String getFirstName() => _name;
To retrieve this value, a function call is required, for example,
Person.getFirstName(); however, it may be preferable to have a property syntax such as
Person.firstName. Having private fields and retaining the property syntax in this manner is possible using the
The syntax of Dart also supports
set via keywords:
int get score => score ...