Getters and Setters, also called accessors and mutators, allow the program to initialize and retrieve the values of class fields respectively.
Getters or accessors are defined using the get keyword.
Setters or mutators are defined using the set keyword.
A default getter/setter is associated with every class. However, the default ones can be overridden by explicitly defining a setter/ getter. A getter has no parameters and returns a value, and the setter has one parameter and does not return a value.
Syntax:Defining a getter
Return_type get identifier
Syntax:Defining a setter
The following example shows how you can use getters and setters in a Dart class:
Please Login to comment...