DEV Community

Discussion on: Flutter Performance Tips (#1): const constructors

Collapse
 
dqk profile image
K

Hi. Why the first one is bad and the second one is good? Can you give me an explanation? Tks.

Collapse
 
pedromassango profile image
Pedro Massango

In short, because when you mark the top-most widget in the tree with a const keyword, all its inner widgets will also use a const constructor, so there is no need to add those extra const keywords. If a inner widget does not have a const constructor, then your code won't compile.