The following code has the same effect, butuses the optional new
keyword before the constructor name:
var p1 = new Point(2, 2);
Version note: The new
keyword became optional in Dart 2.
Constructing two identical compile-time constants results in a single,canonical instance:
var a = const ImmutablePoint(1, 1);
assert(identical(a, b)); // They are the same instance!
Within a constant context, you can omit the before a constructoror literal. For example, look at this code, which creates a const map:
// Only one const, which establishes the constant context.
'point': [ImmutablePoint(0, 0)],
'line': [ImmutablePoint(1, 10), ImmutablePoint(-2, 11)],
};
If a constant constructor is outside of a constant contextand is invoked without ,it creates a non-constant object:
Version note: The const
keyword became optional within a constant context in Dart 2.