Instance Variables

Instance variables are nothing more than variables declared inside a class.

 
class​ ComicsView {
 
ComicsCollection collection;
 
ComicModel model;
 
Element el;
 
// ...
 
}

In this case, we have declared three instance variables of different types. We could have declared all three as having a variable type (var collection, model, el;), but we are being good library maintainers by being explicit about the types.

Instance variables are accessible throughout the class with just their name—there is no need to prepend this. to a variable unless it would help to disambiguate an instance variable from a local variable.

By default, instance variables are public, which means they are accessible by subclasses and outside the class. ...

Get Dart 1 for Everyone now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.