When a method is called on an object, and this method does not exist in its class, or any of its superclasses in the inheritance tree, then
Object is called. The default behavior of
noSuchMethod is to throw a
NoSuchMethodError, method not found: 'methodname'. However, Dart can do more; as in some other dynamic languages, every class can implement
noSuchMethod to make its behavior more adaptive and flexible. This is because of the fact that Dart is dynamically typed, so it is possible to call a method that does not exist in a dynamic variable. In Java, you get a compile time error for this. In Dart too, an error is thrown but at runtime. By using
noSuchMethod(), we can circumvent this and put it to our use. ...