In Dart, I see that it is possible to create const constructors within a class. Is it possible to mix a normal and const constructor within a class using the same fields? Or is it intended to always separate classes used for purposes of creating mutable and immutable instances?
I have tried creating a normal and const constructor in the same class. The issue is const constructors require final fields, and so if a normal constructor were to use these fields, then its instance fields would be immutable.
void main() {
Jank fj = Jank.normal(5, 'LOL');
const cj = const Jank.fixed(6, 'HA');
fj.a = 123; //cannot do this, but want to
cj.a = 456; //cannot do this, is expected
}
class Jank {
final int a;
final String b;
Jank.normal(this.a, this.b);
const Jank.fixed(this.a, this.b);
}
I want to be able to use immutable fields when using the const constructor, and use mutable fields when using the normal one. It seems to be one or the other.