Final vs const in Dart

What’s the difference between final and const in Dart?

Easy!

Final means single-assignment.

Const means immutable.

Let’s see an example:

final _final = [2, 3];
const _const = [2, 3];
_final = [4,5]; // ERROR: can't re-assign
_final.add(6); // OK: can mutate
_const.add(6); // ERROR: can't mutate
Want to know EVERYTHING about Dart constructors? Check out Deconstructing Dart Constructors!

Need professional help with Flutter?

Describe your project in detail and include your e-mail and budget.