I have a method that I'm overriding:

@override
bool operator ==(Object o) {
  if (identical(this, o)) return true;

  return o is Song &&
      o.id == id &&
      o.name == name &&
      o.lyrics == lyrics &&
      o.url == url;
}

But I get a lint warning from flutter_lints:

Don't rename parameters of overridden methods. dart(avoid_renaming_method_parameters)

What is it complaining about? How do I fix it?

I found the answer so I'm posting below.


Solution 1: Suragch

When you override a method that takes parameters, you should use the same parameter names as the original method from the super class. If you don't know what they are, look at the super class source code to find out.

In your case you have:

@override
bool operator ==(Object o) {
  // ...
}

But if you look at the source code of the super class (probably Object unless you have some other class that was overriding the equality operator), you'll see the following:

external bool operator ==(Object other);

So to get rid of the warning you should change o to other:

@override
bool operator ==(Object other) {
  // ...
}


Solution 2: jamesdlin

In general, when you get a complaint from the analyzer, you can search for the lint ID reported in the warning message. In this case, that's avoid_renaming_method_parameters. The documentation for the avoid_renaming_method_parameters lint explains what triggers it and why:

Methods that override another method, but do not have their own documentation comment, will inherit the overridden method's comment when dartdoc produces documentation. If the inherited method contains the name of the parameter (in square brackets), then dartdoc cannot link it correctly.

So even though the name of a positional parameter normally doesn't matter, the avoid_renaming_method_parameters lint triggers if both:

  • The parameter name is different from the overridden method's.
  • The override does not provide its own dartdoc comment.