When using a ListView in flutter to retrieve a list of json objects from an API. Is it the right way to have an Stateful or Stateless Widget?

Issue

So say I have a simple app with 2 routes. The home route is profile and the second is items. So the idea is that when the user clicks in the item icon the app should move to that route and display all the user’s items. The question is should this item Widget be Stateless or Stateful? Take in consideration that I expect the user to pull to refresh this Route and reload the api in the Listview.

Solution

It should definitely be a Stateful widget since you are expecting data from an API. A stateless widget can’t change, you should only use a Stateless widget if the data on the page is static.

Answered By – Becca

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published