From Why does Dart have compile time constants?:
Dart has the concept of compile-time constants. A compile-time constant is parsed and created at compile time, and canonicalized.
For example, here is a
const
constructor for Point:class Point { final num x, y; const Point(this.x, this.y); }
And here's how you use it:
main() { var p1 = const Point(0, 0); var p2 = const Point(0, 0); print(p1 == p2); // true print(p1 === p2); // true }
This code snippet was from Stack Overflow I am reusing this good example, thanks again. Const I have noticed is used alot in flutter widgets.
Does that mean that we can use const
to create Singleton Objects?