Reputation: 899
How come in dart in a line of code such as this one:
MaterialPageRouter(builder: (context) => MyWidget())
We are returning MyWidget class with out instantiating it with the keyword new as in new MyWidget()
? Are we just returning the class itself and something happens under the hood that uses the new keyword
to do whats required. Or something else is happening?
Upvotes: 5
Views: 404
Reputation: 657871
new
became optional in Dart 2. You can just omit it or write it. It doesn't make a difference.
MyWidget()
creates a new instances and this is what is returned.
Upvotes: 4