filiph / state_experiments

Companion repository to the "Build reactive mobile apps in Flutter" talk

Home Page:https://www.youtube.com/watch?v=RS36gBEp8OI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is the purpose of Unmodifiable ListView ?

ejabu opened this issue · comments

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.