I am having trouble understanding how constant constructors and the constructor initializer list in dart.
I have this small code:
class A {
const A();
}
class B {
const B();
final A a = const A();
}
class C {
const C(): a = const A();
final A a;
}
class D {
const D(): b = const B();
final B b;
}
class E {
const E(): a = const B().a; // <- Lint: Invalid constant value
final A a;
}
All of these classes and their constructors are legit. Except for E and E() constructor.
What I don't understand is that the D constructor is valid:
const C(): a = const A();
But E is not valid:
const E(): a = const B().a; // <- Lint: Invalid constant value
It kind of confuses me, why does B() can be a constant value and B().a is not? I would have thought if an object is a constant constructor, B().a would have been a constant value too.
What am I missing here?