Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'new' keyword in dart

Tags:

flutter

dart

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?

like image 731
unbalanced_equation Avatar asked Dec 07 '18 19:12

unbalanced_equation


1 Answers

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.

like image 152
Günter Zöchbauer Avatar answered Oct 18 '22 06:10

Günter Zöchbauer