Defining Constants
Explore how to define variables with unchanging values in Dart using final and const. Understand the difference between compile-time and run-time, and learn when to use each keyword to ensure your program maintains fixed values appropriately.
Overview
Sometimes we create a variable and assign it a very specific value with the intention of never changing the value. For the program to run successfully, it is of the utmost importance that the value of the variable remains the same throughout its lifetime. To create such a variable, the keywords final and const should be used. Before we get into what final and const actually do, we need to learn the difference between compile-time and runtime.
Compile-time and run-time
Compile-time and runtime are programming terms that refer to different stages in a program’s lifetime. In order to create a program, you first write some source code. The ...