Final and Const

If you never intend to change a variable, use final or const, either instead of var or in addition to a type. A final variable can be set only once; a const variable is a compile-time constant.


Here’s an example of creating and setting a final variable:

final name = 'Bob'// Without a type annotation

final String nickname = 'Bobby';



You can’t change the value of a final variable:

name = 'Alice'// Error: a final variable can only be set once.



Use const for variables that you want to be compile-time constants

const bar = 1000000// Unit of pressure (dynes/cm2)

const double atm = 1.01325 * bar; // Standard atmosphere



Conclusion:

Const
Value must be known at compile-time, const birthday = "2008/12/26"
Can't be changed after initialized.

Final
Value must be known at run-time, final birthday = getBirthDateFromDB();
Can't be changed after initialized.