Closed UkiDelly closed 4 months ago
Any class used through a generic type must be initialized beforehand.
Do TermModelMapper.ensureInitialized()
In this situation, there is only one TermModelMapper
, but if there are more models used as generics, will there be no choice but to hardcode .ensureInitialized()
of all models?
Check out https://pub.dev/documentation/dart_mappable/latest/topics/Generics-topic.html#generated-initializer
Unfortunately this can't be done fully automatically since Dart does not have static initialization of classes.
I was trying to use generic to decode the json into a different model depending on the data I received from the network communication. The problem is when it try to decode from json (either string and map), it cause an error of
How could I solve this problem?
This is the
BaseResponse
model that I use to convert the response from the network.And also
SuccessModel
is using generic tooI am using this
TermModel
to test itThis is the code I test
Then this is the
output