Tutorial by Examples

Classes can be created as follow: class InputField { int maxLength; String name; } The class can be instantiated using the new keyword after which the field values will be null by default. var field = new InputField(); Field values can then be accessed: // this will trigger the sette...
A class can have members. Instance variables can be declared with/without type annotations, and optionally initialized. Uninitialised members have the value of null, unless set to another value by the constructor. class Foo { var member1; int member2; String member3 = "Hello world!&q...
A class constructor must have the same name as its class. Let's create a constructor for a class Person: class Person { String name; String gender; int age; Person(this.name, this.gender, this.age); } The example above is a simpler, better way of defining the constructor than the...

Page 1 of 1