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

why 'A freezed union cannot have private constructors'? #744

Closed
IlyaMax opened this issue Aug 24, 2022 · 8 comments
Closed

why 'A freezed union cannot have private constructors'? #744

IlyaMax opened this issue Aug 24, 2022 · 8 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@IlyaMax
Copy link

IlyaMax commented Aug 24, 2022

Is your feature request related to a problem? Please describe.
I use flutter bloc and freezed for events. but some of them are used internally in bloc only so it would be very useful if it could be possible to hide them.

Is there some explanation why this made like that? Maybe it causes any problems?

@IlyaMax IlyaMax added enhancement New feature or request needs triage labels Aug 24, 2022
@rrousselGit
Copy link
Owner

Because it's not possible to have private named parameters.

So freezed cannot generate something like when(_union: ..., _union2: ...)

@IlyaMax
Copy link
Author

IlyaMax commented Aug 24, 2022

But what if it would be accessible in when/map/etc but we could NOT create instance of it? Again for events it looks not bad, but maybe I miss something

@IlyaMax
Copy link
Author

IlyaMax commented Aug 24, 2022

I mean generator looks for constructors names with _ and instead of creating when(_union: ..., _union2: ...) it generateswhen(union: ..., union2: ...)

@rrousselGit
Copy link
Owner

We could, yes.
But then that'd mean the private constructors would leak into the public API.

In that case, they might as well be public

@rrousselGit rrousselGit added question Further information is requested and removed needs triage labels Sep 27, 2022
@IlyaMax
Copy link
Author

IlyaMax commented Sep 27, 2022

@rrousselGit I understand that some api will leak but at least we could forbid the construction of models. So we could create instances of models within library only

@rrousselGit
Copy link
Owner

You could annotate the constructor with @visibleForTesting then

That would achieve roughly the same thing.

@IlyaMax
Copy link
Author

IlyaMax commented Sep 27, 2022

Yeap, thx, I think that's enough for my case

@rrousselGit
Copy link
Owner

Closing in favor of #925

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants