@override annotation is a metadata marker defined in dart:core used to explicitly declare that an instance member is intended to replace a member inherited from a superclass or implement a member defined in an interface. Its primary function is to trigger a specific static analysis check that validates the existence of the overridden member in the inheritance hierarchy.
Syntax
The annotation is placed immediately preceding the declaration of a method, getter, setter, operator, or instance field.Static Analysis Behavior
The presence of the@override annotation triggers a specific validation logic within the Dart analyzer regarding member existence, distinct from general type system rules.
Existence Check
When a member is annotated with@override, the analyzer performs a lookup in the class’s type hierarchy (including extended classes, mixed-in types, and implemented interfaces). It verifies that a member with the exact same name exists in a direct or indirect supertype.
If the analyzer fails to find a matching member in the supertypes, it emits the compile-time error: override_on_non_overriding_member.
Interaction with Type Safety
The@override annotation does not alter the rules regarding Signature Compatibility (covariant return types and contravariant parameter types). The Dart language specification enforces signature compatibility on all overriding members regardless of whether the @override annotation is present. The annotation serves strictly to validate the intent to override, preventing accidental non-overrides (such as typos in method names).
Scope of Application
The annotation applies to instance members only. It is valid for:- Methods
- Getters and Setters
- Operators
- Instance Fields: Applying the annotation to a field asserts that the implicitly generated getter (and setter, if non-final) overrides a member in a supertype.
@override to static members or constructors, as these members are not inherited and therefore cannot participate in polymorphism.
Master Dart with Deep Grasping Methodology!Learn More





