final variable in Dart is a single-assignment variable. Once a final variable is initialized, its memory reference is locked and cannot be reassigned to a new value. Unlike compile-time constants (const), final variables are evaluated at runtime. Top-level and static final variables are lazily initialized upon their first read, whereas instance variables are evaluated at instance creation.
Syntax and Type Inference
You can declare afinal variable with an explicit type or rely on Dart’s type inference. If the type is omitted, the analyzer infers it from the assigned value.
Local Scope Assignment Rules
Afinal variable must be assigned exactly once before it is read. Within a local scope (such as a function body), a final variable can be declared uninitialized (a “blank final”) as long as the compiler can guarantee it is assigned before its first use.
Late Initialization
Due to Dart’s sound null safety, top-level and instancefinal variables must typically be initialized at declaration or during object construction. To declare an uninitialized top-level or instance final variable that will be assigned exactly once at a later point, you must use the late final modifier.
Runtime Evaluation
Becausefinal variables are evaluated at runtime, they can be assigned values derived from function calls, object instantiations, or other runtime calculations.
Shallow Immutability
Thefinal keyword enforces reference immutability, not object immutability. If a final variable holds a reference to a mutable object (like a List or Map), the internal state of that object can still be modified. The restriction only prevents the variable identifier from pointing to a completely different object in memory.
Class Instance Variables
When used as instance variables within a class,final fields must be initialized before the constructor body executes (unless marked late). This can be done at the point of declaration, via initializing formal parameters, or within the constructor’s initializer list.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More





