Flutter Newbie
Flutter Newbie

Reputation: 420

Why does Android Studio add "const" to widgets?

I'm learning Flutter right now with an Udemy course. The instructor always writes the code like this:

padding: EdgeInsets.all(8.0),

However in Android Studio, when you add "wrap with padding" it adds const (isn't this a unchangeable variable?). Also in Flutter documentation it has always used const.

padding: const EdgeInsets.all(8.0),

Upvotes: 1

Views: 540

Answers (1)

Jorge Vieira
Jorge Vieira

Reputation: 3072

If you know the values will not change along the screen lifecicle is better use const variables, they are better for the performance. But you can do without const, the difference is not so big. See this thread: What is the difference between the "const" and "final" keywords in Dart?

Upvotes: 3

Related Questions