I came across this article in which the author says that it’s more performant defining a file with all SizedBox
width and height constants that is going to be imported each time a SizedBox
is needed.
Is it true? Or how can we confirm what he says is true?
Or, what happens if I use his approach, would it be counterproductive?
2
Answers
From the article:
so the thing is not that wer’e creating a separate file, but rather the point is that we’re creating
const
antsThe reason why
SizedBox
is better, since it can beconst
which is immutable and created in compile time so it’s faster.For example, this code works:
But this code will fail:
Also, take a look at the docs:
See also
const
means that the following object can and will be instantiated before the program is run.So I don’t think it will be more performant, its same.
but I guess its just better approach, to write your
const SizedBox
in separate file compare to write at each time, less typing and clarification as mentioned in the article.