Junhan Chen
Junhan Chen

Reputation: 23

Flutter why need new when create widget?

Padding(
  child: Icon(Icons.search)
);

new Padding(
  child: new Icon(Icons.search)
);

The above two pieces of code achieve the same effect, when do us need to add "new"?

Upvotes: 1

Views: 117

Answers (2)

Rubens Melo
Rubens Melo

Reputation: 3305

Since Dart 2.0 , new keyword is optional.

Upvotes: 4

Jimmy Chen
Jimmy Chen

Reputation: 187

Flutter need 'new' keyword in the lower version when create a object. In the newest version, 'new' keyword can be ignored

Upvotes: 0

Related Questions