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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With