!) is a postfix unary operator that casts a nullable expression (T?) to its underlying non-nullable type (T). It asserts to both the static type checker and the runtime environment that the operand is not null.
Syntax
Static Type Mechanics
At compile time, the! operator performs a hard cast. It instructs the Dart analyzer to treat the expression as known non-nullable, overriding standard control flow analysis. This promotes the static type from nullable to non-nullable, permitting member access or assignment to non-nullable variables.
Runtime Mechanics
At runtime, the operator evaluates the operand:- If the operand is not null: The expression evaluates to the value of the operand.
- If the operand is null: The operator throws a
TypeError, halting execution.
Operator Precedence
The null assertion operator is a postfix operator. It shares the highest precedence level with method selectors (.), subscript operators ([]), and function calls (()). It binds more tightly than prefix operators (such as unary negation - or the logical NOT operator !) and arithmetic operators.
Master Dart with Deep Grasping Methodology!Learn More





