Open befora opened 5 months ago
I removed these lines from the generated morphy.dart file and it solved the issue.
// ignore: unused_field
Map<Type, Object? Function(Never)> _fns = {};
Map<String, dynamic> toJson_2([Map<Type, Object? Function(Never)>? fns]) {
this._fns = fns ?? {};
return toJson();
}
Thanks @befora, this is indeed a bug. It looks like the json functionality and the constant functionality don't work together. I'll fix this hopefully in a couple of weeks and batch some other changes up.
As a workaround you can either set the generate json to false @Morphy(generateJson: false) or you can make the class a non constant.
Perhaps it might be a rarity to have a constant that you serialize anyway as the constant value would be known at compile time??? I may be missing an edge case though and will fix it regardless.
Example to recreate issue:
I get this error: