How to use factory const constructors? How to use factory const constructors? dart dart

How to use factory const constructors?


Dart doesn't execute Dart code during compilation. This is the reason const constructors can't have a body and why there is no other way to work around this limitation.

If you want to execute code when an instance is created, just don't make use of const. Const isn't that important in Dart anyway. There were even discussions to remove it from the language because the benefits are not big enough.