1

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),
BZKN
  • 1,499
  • 2
  • 10
  • 25
Flutter Newbie
  • 350
  • 1
  • 3
  • 12

1 Answers1

3

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?

Jorge Vieira
  • 2,784
  • 3
  • 24
  • 34
  • I know "const" and "final" keywords. But i wonder why just make something more complicated when it works? – Flutter Newbie Apr 18 '21 at 22:29
  • 1
    @FlutterNewbie Just because something works one simpler way doesn't mean you should do it. – Christopher Moore Apr 18 '21 at 22:40
  • 1
    I think is like a suggestion that using const is better, so use when possible, guess we should not use only when is a runtime calculated value that is impossible to use const. But the smartphones hardware are so powerful today so doesn't makes much difference anyway ;) – Jorge Vieira Apr 18 '21 at 22:41