Skip to content
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

Cannot populate the required constructor argument: elementInfo. It is assigned to a field not meant to be used in fromJson. #1384

Open
MikePendo opened this issue Dec 26, 2023 · 2 comments

Comments

@MikePendo
Copy link

Hi,
So I guess my issue coz of some generics that I used I am wondering if there is some work around.
So in general I have a Tree, TreeElement, and ElementInfo

class DataTree implements Tree<TreeElement, Element> {
    late TreeElement _root;
...
}
class TreeElement<T extends InternalElementTreeInfo> implements TreeNode {
 T _elementInfo;
 TreeElement({ required T elementInfo }) : _elementInfo = elementInfo; <-- This is line 18

on dart run build_runner build --delete-conflicting-outputs
I got the following error:
Cannot populate the required constructor argument: elementInfo. It is assigned to a field not meant to be used in fromJson. package:pendo_sdk/src/tree/tree_element.dart:18:3
Must admit I dont really understand the error, any suggestion of how I can overcome it?

@MikePendo
Copy link
Author

ok adding

TreeElement._() : _elementInfo = ElementInfo.rootElementInfo() as T;
and using
@JsonSerializable(explicitToJson: true, constructor: '_')
seems like generates without errors

@MikePendo
Copy link
Author

Strange the generation seem fine but when I run my package in the app I get the following error:
Error: Method not found: '_$DataTree'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant