While not mandatory, using the @override
annotation on compliant
members (methods, properties, operators) improves readability by making it explicit that members are overridden.
Unlike other languages, all methods in Dart are virtual
by default. So,
using the @override
annotation prevents accidental overriding of a base class method in a subclass.
Noncompliant code example
class ParentClass {
bool doSomething(){/*...*/}
}
class FirstChildClass extends ParentClass {
bool doSomething(){/*...*/} // Noncompliant
}
Compliant solution
class ParentClass {
bool doSomething(){/*...*/}
}
class FirstChildClass extends ParentClass {
@override
bool doSomething(){/*...*/} // Compliant
}