on Saturday, 18th of July, 2020

Constructors are used to create objects with pre-determined values for the properties. Constructors come in three flavors: the standard constructors, named constructors, and factory constructors. (Factory constructors are discussed on a different page.)

class Cat {
    String name;
    String color;
    // a simple constructor
    Cat(, this.color);

    // named constructors are used to define additional constructors
    // they return a new instance of the class, (but not with a 'return' statement) 
    // usually with some values given defined values. {
        color = 'Orange';
    // this is another named constructor example {
        color = 'Black';
    String toString() => "Cat: ${}, ${this.color}";

void main() {
    print(Cat('nora', 'orange'));
    print(Cat.fromJson({'name': 'Nora', 'color':'Orange'}));

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