rrousselGit / freezed

Code generation for immutable classes that has a simple syntax/API without compromising on the features.
https://pub.dev/packages/freezed
1.91k stars 235 forks source link

Is there a way of making a specific collection unmodifiable when the makeCollectionsUnmodifiable is set to false #947

Open Silfalion opened 1 year ago

Silfalion commented 1 year ago

Is your feature request related to a problem? Please describe. I have 2 unions classes, with a collection each, the collections are different from one another(not the same name). The second class collection need to be unmodifiable while on the other hand the first should be modifiable

Describe the solution you'd like Ideallt, the first class should be modifiable while keeping the second one unmodifiable

Describe alternatives you've considered I didn't see any, at least for now, though maybe a CollectionModifiable or CollectionUnmodifiable annotations would come in handy here?

Additional context

Thank you taking the time to read this issue

rrousselGit commented 1 year ago

You could manually override the getter to return an UnmodifiableListView

Silfalion commented 1 year ago

True, thank you. Though would a PR be welcomed for this? Not necessary now, but I could give it a try if you see it's relevant enough

rrousselGit commented 1 year ago

Not for now. Freezed generally doesn't do field-specific thing. Like how we can't exclude one field from copyWith/==

Silfalion commented 1 year ago

I understand. Well, thank you for your answer, appreciate it