What is the difference between final, const, and static in Dart?
TL;DR: final means assigned once at runtime; const means assigned at compile-time (deeply immutable); static means the field belongs to the class itself, not instances — these are orthogonal concepts.
Full Answer
final
A final variable is assigned exactly once. The assignment can be computed at runtime. Once set, it cannot be reassigned. Objects referenced by a final variable can still be mutated.
const
A const variable is a compile-time constant — its value must be computable at compile time. const creates deeply immutable, canonicalized objects. Two const constructors with identical arguments produce the exact same object in memory.
static
static means the member belongs to the class type rather than to instances. A static field is shared across all instances. It can be final or const.
| Aspect | Keyword | Key property |
|---|---|---|
| final | Set once, runtime value OK | Variable not reassignable |
| const | Compile-time value, canonicalized | Deeply immutable, same instance |
| static | Belongs to class, not instance | Shared across all instances |
Code Examples
true (implementation-defined) DartDosage 2
Common Mistakes
- ✗Using final when you need const — you miss compile-time canonicalization and the small performance benefit.
- ✗Thinking final prevents object mutation — final only prevents reassignment, the object can still change.
Interview Tip
const objects are canonicalized: const Color(0xFF5B4FE8) anywhere in the codebase is always the exact same Color object in memory. This is why Flutter's const constructors are a performance optimization.