-
-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend non-freezed base classes #464
Comments
Extending any object is not supported at the moment. |
I found a workaround turning Foo into a mixin. But that doesn't work for 3rd party code... |
Don't use inheritance. Use composition @freezed
class Bar with _$Bar {
const factory Bar({
required Foo foo,
}) = _Bar;
} |
I don't really plan working on this, but if someone wants to, I think we could consider a We'd probably want to support both: @Super('foo: foo');
factory ...
@Super('super.named(foo: foo)');
factory ... |
Could you expand the example a little bit, please? |
Greate news, thanks. |
any update on this? |
did you get the solution sir? |
Like I said before, I don't plan on working on this. I'm waiting for metaprogramming. |
In the meantime, is there a recipe for annotating a composed object when the JSON we are parsing is flat as a serialized inherited would be? Or is that more of a question for the json_serializable folks? |
without inheritance it's hard to create base state in abstract class. composition is not working well in abstract as we don't know what subclasses are doing and there is no way letting them to override super class state type. |
How do we reuse the json parsing with composition? Switching from inheritance to composition breaks the object hierarchy. The toJson of inheritance version would be like: {"fooKey": "foo", "barKey": "bar"} The toJson of composition version would be like: {"barKey": "bar", "foo": {"fooKey": "foo"}} Any way for composition to maintain the same json structure as the inheritance one? |
Could we get an answer to this? I have 5 properties that are shared across all of my classes. The backend provides the json in a flat format so I can't use the nested composition as suggested. |
Here, we have a non-freezed base
Foo
(potentially coming from a 3rd party lib) and want to extend it with a subclass that uses@freezed
.The text was updated successfully, but these errors were encountered: