'functioning of covariant in flutter

I was going through dart documentation and there I came across this code and this term covariant. I went through some documentation but I didn't get what is its function there. A detailed explained answer is always appreciated.

class Animal {
  void chase(Animal x) { ... }
}

class Mouse extends Animal { ... }

class Cat extends Animal {
  @override
  void chase(covariant Mouse x) { ... }
}


Solution 1:[1]

By using the covariant keyword, you disable the type-check and take responsibility for ensuring that you do not violate the contract in practice.

As you can see in the example, if you are overriding a method, its params should also be the same. But if you are using covariant, it will allow you to use Mouse instead of Animal.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abhishek Doshi