1

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 the selectedItem 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 the StatelessWidget 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?

Pablo Cegarra
  • 20,955
  • 12
  • 92
  • 110
Magnus
  • 17,157
  • 19
  • 104
  • 189
  • This might just be a different way to phrase your first idea, I'm not sure. What I would try is to make the onTap send a string to the model, changing the value of the selected item. The model then changes all of the variables for the images and strings used by the second page. The second page then loads. – scottstoll2017 Feb 21 '19 at 12:15

0 Answers0