Dart Constants are immutable objects, which means that they can’t be changed or modified during the execution of the Dart program. Once we initialize the constant with a value, it cannot be reassigned in the program. Dart will throw an exception if we try to modify the constant.
The Dart constants can be defined using the following keywords:
- final keyword
- const keyword
These keywords can be used with or without a data type name.
The final keyword denotes a single-time assignment of the variable. We can define the constant by using the final keyword. The general syntax to define a constant using the final keyword is as follows:
final data_type constant_name
final int MAX_ELEMENTS = 10;
The const keyword represents the compile-time constant. We can define a constant by using the const keyword. The syntax is as follows:
const data_type constant_name
const String bank_name=”Bank of America”;
Dart tutorial on this website can be found at:
More information on Dart: