'The constructor being called isn't a const constructor. Try removing 'const' from the constructor invocation. Flutter How to solve?

I'm getting this error when I tried to build Object using Freezzed Package in Flutter Errors Screenshot

enter image description here

If I tried to use some other datatypes instead of DateTime I'm not getting any errors

enter image description here

How to solve this? Thank you

pubspec.yaml

build_runner: ^2.0.4
freezed: ^0.14.2
json_serializable: ^4.1.3

flutter version: 2.2.1



Solution 1:[1]

The error is causing because DateTime.now() can never be const it will change value of DateTime.now() whenever this class (PracticalModel()) gets instantiated.

Try removing const from your class

//...
// remove const from here.
factory PracticalModel({//...})
//...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chirag Bargoojar