Last Updated on 2021-10-16 by Clay
"new" keyword
When I jumped into Flutter learning, what bothered me most at first was as stated in the title of this article: When should I use the new
keyword? Some tutorial will add new
for declaring variable, but some tutorials will not.
And these sample codes are workable.
The conclusion is: you can add new
or not.
In Dart 2, the new
keyword is optional. If you want, you can continue to ignore it, and this will not have effect on your program.
The following is the official description:
References
- https://stackoverflow.com/questions/50091389/do-you-need-to-use-the-new-keyword-in-dart
- https://dart.dev/guides/language/language-tour#using-constructors