How To Populate Dropdown List With JSON Data

I have a view that builds the UI first, I also have a future function that runs and gets JSON data which I want to use to populate a dropdown. The problem is the data arrives after the view is built, I have tried calling setState but I somehow don’t feel that it’s the correct thing to do as setState redraws the whole view and not just the dropdown.

So how would I populate my dropdown with the items retrieved from my future JSON function?

1 Like

Yes, the ideal way is to show a loader till all Async contents are not loaded on the screen or of that particular element.

You can have an isLoading property and set it false once the API request is complete.

The Dropdown should be loaded once isLoading becomes false.


Other option is to use a FutureBuilder.
This widget is handy when you are dealing with Future calls.

1 Like