freezed
freezed copied to clipboard
why 'A freezed union cannot have private constructors'?
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?
Because it's not possible to have private named parameters.
So freezed cannot generate something like when(_union: ..., _union2: ...)
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
I mean generator looks for constructors names with _ and instead of creating when(_union: ..., _union2: ...) it generateswhen(union: ..., union2: ...)
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 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
You could annotate the constructor with @visibleForTesting then
That would achieve roughly the same thing.
Yeap, thx, I think that's enough for my case
Closing in favor of https://github.com/rrousselGit/freezed/issues/925