0PricingLogin
Dart Academy · Lesson

Getters and Setters

Expose computed and guarded properties.

Beyond Plain Fields

Sometimes you want a property that is computed or guarded. Dart offers getters and setters to control how a value is read and written.

What a Getter Is

A getter looks like a field from outside but runs code to produce its value. Use the get keyword to define one.

int get area => width * height;

All lessons in this course

  1. Defining a Class With Fields
  2. Instance Methods and this
  3. Getters and Setters
  4. Static Members and Class Constants
← Back to Dart Academy