I have two classes: BaseClass (BaseResponse) and DerivedClass (LoginResponse). I am de-serializing them using the fromJson method.
I want to understand how can I call the fromJson method for the base class.
class BaseResponse {
int responseCode;
String responseMessage;
BaseResponse.fromJson(Map<String, dynamic> input)
: responseCode = input["ResponseCode"],
responseMessage = input["ResponseMessage"];
}
class LoginResponse extends BaseResponse {
String authenticationToken;
LoginResponse.fromJson(Map<String, dynamic> input)
: authenticationToken = input["AuthenticationToken"];
}
LoginResponse.fromJson(Map<String, dynamic> input)
gives me an error saying: The class 'BaseResponse' doesn't have an unnamed constructor.
Any help is appreciated.
Thanks.
I wouldn't make a .fromJson for the BaseResponse unless you absolutely need it for some reason.
A better approach in my opinion would be declaring final variables in the base class and asserting expressions there, and only implementing the model or any sort in the derived classes: