Using class members

Objects have members consisting of functions and data (methods andinstance variables, respectively). When you call a method, you _invoke_it on an object: the method has access to that object’s functions anddata.

Use a dot (.) to refer to an instance variable or method:

  1. var p = Point(2, 2);
  2. // Set the value of the instance variable y.
  3. p.y = 3;
  4. // Get the value of y.
  5. assert(p.y == 3);
  6. // Invoke distanceTo() on p.
  7. num distance = p.distanceTo(Point(4, 4));

Use ?. instead of . to avoid an exceptionwhen the leftmost operand is null:

  1. // If p is non-null, set its y value to 4.
  2. p?.y = 4;