What are Dart const constructors?

Last reviewed in January 2020 by Frank Treacy

For example, what's const in var title = const Text('Hi!')?

A const constructor is an optimization! The compiler makes the object immutable, allocating the same portion of memory for all Text('Hi!') objects.

But not Text(Math.random()) though, as its value can't be determined at compile time!

Want to know EVERYTHING about Dart constructors? Check out Deconstructing Dart Constructors!

The best from the Flutter-verse in 3 minutes or less? Join Snacks!

Delivered twice monthly. No link walls. No spam. EVER.