I mean what is difference between : ” const list =[1,2,3]
” and “var list= const[1,2,3]
“
The difference is in the immutability and the way the list is declared.
const list = [1, 2, 3] declares a constant list, that is a compile-time constant, meaning its value is determined at compile time and cannot be changed at runtime.
var list = const[1, 2, 3] declares a variable that holds a constant list, but the value of that variable can be changed to a different list later in your code.
void main() {
const list1 =[1,2,3];
var list2 = const[1,2,3];
list1.add(4); // <--error
list2.add(4); // <--error
list1 = [5]; // <--error
list2 = [5];
list2.add(6);
print(list2);
}