!) is a unary postfix operator that converts an expression of a nullable type (T?) to its underlying non-nullable type (T). It explicitly asserts to the compiler that the operand is not null at the specific point of evaluation, overriding static null-safety checks.
Syntax
Static Analysis Behavior
The operator changes the static type of the expression fromT? to T. This allows the resulting value to be assigned to non-nullable targets, passed as non-nullable arguments, or used to access members defined on T. Unlike type promotion via control flow analysis (e.g., if (val != null)), the ! operator enforces the type change unconditionally for that specific expression.
Runtime Behavior
The operator executes a mandatory check on the operand at runtime:- Success: If the operand evaluates to a non-null value, the expression evaluates to that value.
- Failure: If the operand evaluates to
null, the runtime throws aTypeError(typically with the message “Null check operator used on a null value”). This behavior applies to both the Dart VM (Native) and Dart for the Web.
Code Illustration
Master Dart with Deep Grasping Methodology!Learn More





