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

What is the purpose of Unmodifiable ListView ? #5

Closed
ejabu opened this issue Jul 23, 2018 · 1 comment
Closed

What is the purpose of Unmodifiable ListView ? #5

ejabu opened this issue Jul 23, 2018 · 1 comment

Comments

@ejabu
Copy link

ejabu commented Jul 23, 2018

UnmodifiableListView<CartItem> get items => UnmodifiableListView(_items);

I prefer to try bloc_start architecture.

Is it okay to change this to normal ListView ?

What is the purpose of this actually ?

@filiph
Copy link
Owner

filiph commented Jul 24, 2018

Oh, definitely okay to use List.

UnmodifiableListView is there for safety. It's immutable, so consumers of the Cartclass cannot change the items in the class via the Cart.items getter. They have to go through Cart.add() and Cart.remove() (which make sure to do the right thing).

So, this is just a bit of encapsulation. For a smaller project and for learning purposes, it's okay to use a List.

I'm closing this but feel free to reopen if it's not clear or helpful.

@filiph filiph closed this as completed Jul 24, 2018
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

2 participants