Properties and methods

on Saturday, 18th of July, 2020

The interface of an object is exposed via instance properties and instance methods.

These are the most "basic" members on a class.

Properties

Properties are variables of any type defined on the class.

class Cat {
  String name; // property
  String color; // property
  int age; // property
}

// useage:
var cat = Cat();
cat.name = 'Wallace'; 
print(cat.name);

Methods

Methods are functions on a class that provide behavior for an object. Instance methods on objects are exposed via instances of the class. They have access to other variables and methods on the instance, as well as the keyword this.

class Cat {
  String name; // property
  String color; // property
  int age; // property

  void talk() {
   print('meow!');
  }
}

// useage:
var cat = Cat();
cat.talk();


Join thousands of Flutter developers.

Sign up for infrequent updates about Flutter and Dart.

You can get all this content and more in one place. Check out my new book Flutter in Action