Last updated 4 years ago
There are no access modifier keyword in dart
public , private , protected keyword don't exist in dart.
You can prepend something with _ to make it private in library level
class Employee { String name; String _position; } void main() { var employee1 = Employee(); employee1.name = "John Doe"; employee1._position = 'CTO'; print('${employee1.name}: ${employee1._position}'); }
import 'a.dart'; void main() { var employee2 = Employee(); employee2.name = "Jane Doe"; employee2._position = "CEO"; // Will Show error // employee1._position = 'CEO'; print('${employee2.name}'); }