Why there is an error, when the foo is already a const value?
const foo = const [10, 20];
const bar = foo[0] * 2; // error: const variables must be initialized with a constant value.
asked Oct 14, 2019 at 9:08
user6274128
1 Answer 1
That's because while the variables used to create your second constant are constants, you also used the operator [] – which is not compile-time constant.
So while you can do:
const a = 42;
const b = a * 3;
you cannot do:
const array = [42];
const b = a[0];
answered Oct 14, 2019 at 9:52
Rémi Rousselet
280k89 gold badges560 silver badges456 bronze badges
Sign up to request clarification or add additional context in comments.
lang-dart