Syntax
To override a getter, the subclass defines a getter method with the same name as the superclass property. The@override annotation is used to flag the intention to the compiler, ensuring static analysis checks the relationship between the parent and child members.
Technical Mechanics
Implicit and Explicit Overrides
Dart generates implicit getters for all instance variables (fields). Consequently, a subclass can override an explicit getter (defined with theget keyword) or an implicit getter (generated by a field declaration) using the same syntax. This allows a subclass to replace a stored memory field in the parent with a computed property in the child.
Mutability and Interface Compliance
When overriding a property, the subclass must satisfy the full interface implied by the superclass member. The mutability of the superclass property dictates the overriding requirements:- Final Fields/Getters: If the superclass member is
finalor defines only a getter, the subclass may override it with a getter or a final field. - Non-Final Fields: If the superclass member is mutable (non-final), it implicitly defines both a getter and a setter. A subclass cannot override only the getter for a non-final field; it must override both the getter and the setter to fulfill the interface contract. Failing to do so results in a compile-time error.
Return Type Covariance
The return type of the overridden getter must be covariant with the superclass definition. The return type in the subclass must be the same as, or a strict subtype of, the return type defined in the superclass. This guarantees type safety when a subclass instance is upcast to the superclass type.Super Delegation
Thesuper keyword provides access to the getter implementation of the immediate superclass. This allows the overriding getter to extend the existing logic by invoking the parent’s computation before applying additional transformations.
Master Dart with Deep Grasping Methodology!Learn More





