Recently started following the flutter udacity course and while experimenting with creating basic apps I came across something that was unclear to me. When adding widgets, I have noted that doing both new Widget()
and Widget()
[where Widget is any widget being added to the tree] give the same result. Is there a specific time when you should use new Widget()
and a time when you should omit the new
keyword?
For example:
return MaterialApp(
debugShowCheckedModeBanner: false,
home: new Scaffold(
appBar: new AppBar(
title: Text('My app name')
),
)
Text('My app name')
works, but new Text('My app name')
also works. Any chance I could get some pointers and guidelines on best practices with this?