filiph/state_experiments

What is the purpose of Unmodifiable ListView ?

ejabu opened this issue · 1 comments

ejabu commented

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 ?

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.