Interview frequency: …
Short answer
final means the variable is assigned once at runtime, while const creates a compile-time constant value.
Explanation
Use final when the reference does not change after assignment but the value is only known at runtime, such as a request result or the current time. Use const when the value and all its components are known at compile time; identical const values can share the same canonical instance.
Code example
final currentTime = DateTime.now();
const apiVersion = 2;
const point = Point(1, 2);Common mistakes
- Treating final as a compile-time constant; it is only assigned once.
- Using const with a value that cannot be computed at compile time, such as DateTime.now().