I am developing an app which has one screen showing a list of items, and when the user taps on one item another screen opens up which displays the details of the tapped item.
I'm using the Scoped Model architecture, so the screens are StatelessWidget
's which use the same instance of a concrete Model
.
My problem is that I'm not sure which is the best way to pass information about which item to display to the detail screen.
One way to go is to set a member of the model, e.g.
selectedItem
, to the selected item. This has the advantage of being solely model-based, but it doesn't really feel clean, since theselectedItem
member is useless when not in detail mode (and could potentially contain old data).Another way would be to pass the selected item (or some type of identifier for it) to the
StatelessWidget
constructor and use it to retrieve the correct item from the model in the detail screen. However, this would mean that theStatelessWidget
wouldn't really be stateless, since it would need to store the parameter passed in the constructor in itself...
Is there a third and better way to do it?