Flutter default assignment of List parameter in a constructor

Posted by Andre Scott | Updated on

Flutter default assignment of List parameter in a constructor. Default values currently need to be const. This might change in the future. If your default value can be const, adding const would be enough

Dart usually just assumes const when const is required, but for default values this was omitted to not break existing code in case the constraint is actually removed.

If you want a default value that can’t be const because it’s calculated at runtime you can set it in the initializer list.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers