Open aidanmack opened 1 year ago
Never mind!
I think the fix for my above question would be to write the fromJson as
factory NetworkResponse.fromJson(
Map<String, dynamic> json,
T Function(Object? json) fromJsonT,
) => NetworkResponse.success(fromJsonT.call(json));
Is your feature request related to a problem? Please describe. Yes - Im trying to return my own api return type using Freezed unions.
Describe the solution you'd like
I want to be able create api requests in Retrofit like this where
NetworkResponse
is of type Freezed UnionThe problem is my NetworkResponse data payload needs to be a generic, but then I also need to change the
json
into theTokenApprove
object and I'm not confident with where this should happen.Right now I'm trying to convert it in the method NetworkResponse.fromJson ... But I'm not sure how that function will know how to change the json to
TokenApprove
Describe alternatives you've considered Yeah I've got a static function that once a resonse is returned from the api converts Future to my
NetworkResponse
union. Not ideal though really.