T.Im
T.Im

Reputation: 149

When to use "new" constructor in flutter app?

I have a question about best practice in flutter apps.

When do I need to use the "new" constructor? In the code below, both code snippets are working.

Should I use the "new" constructor anyways, Or only in specific points of the code?

Thank you !!!

return new Container(
  margin: new EdgeInsets.symmetric(
    vertical: 16.0
  ),
  alignment: FractionalOffset.centerLeft,
  child: new Text("TEST")
);

return Container(
  margin: EdgeInsets.symmetric(
    vertical: 16.0
  ),
  alignment: FractionalOffset.centerLeft,
  child:Text("TEST")
);

Upvotes: 0

Views: 84

Answers (1)

Gazihan Alankus
Gazihan Alankus

Reputation: 11984

new is optional starting with Dart 2. You should not use it to stay current with the latest. https://github.com/dart-lang/sdk/issues/30921 https://github.com/dart-lang/sdk/issues/20750

Upvotes: 1

Related Questions