extension_declares_member_of_object
Extensions can't declare members with the same name as a member declared by 'Object'.
Description
#The analyzer produces this diagnostic when an extension declaration declares a member with the same name as a member declared in the class Object
. Such a member can never be used because the member in Object
is always found first.
Example
#The following code produces this diagnostic because toString
is defined by Object
:
extension E on String {
String toString() => this;
}
Common fixes
#Remove the member or rename it so that the name doesn't conflict with the member in Object
:
extension E on String {
String displayString() => this;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.