Using noSuchMethod
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 noSuchMethod() from 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. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access