IT, Programming

Why Flutter Const Constructors

You may wonder why flutter lint sometimes asks you to add const in front of the constructors and sometimes not. As an example of why you add const to this

const Text("Hello World");

And why you don’t add const to this

Text("Hello $name");

That is because adding const in Flutter makes that object immutable. So it allocates only one memory portion for Text(“Hello World”) and your widget will be optimized for the memory. Small things can make a big difference in your app.

What’s your reaction about this article?
+1
0
+1
0
+1
0
+1
0
+1
0

Leave a Reply

Your email address will not be published. Required fields are marked *