Defining Constants
Explore how to define immutable variables in Dart using final and const keywords. Understand the distinctions between compile-time and runtime values, and learn best practices for using these keywords to write reliable, maintainable code.
We'll cover the following...
Sometimes we create a variable and assign it a very specific value with the intention of never changing it. For our program to run reliably, we need a way to ensure that this value remains exactly the same throughout the variable's entire lifetime.
To create variables whose values cannot be changed, Dart provides the final and const keywords. Before we get into how they operate, we need to understand the difference between two stages of a program's life: compile-time and runtime.
Compile-time and runtime
Computers do not understand the Dart source code we write. They only understand machine code.
Compilation is the process of translating our source code into executable ...