0

What is the basic cookbook for a flutter widget that does this?

1) Displays initial state like "loading".

2) Async gets content from a REST API.

3) Updates state when the REST API returns success.

4) Refreshes content on a timer.

dakamojo
  • 1,839
  • 5
  • 21
  • 35

1 Answers1

1

You may want to take a look here.

Generally speaking, you will have a StatefulWidget that calls the API on it's initState and store the "future" (async action in Dart) locally.

Then use FutureBuilder to know weither or not the data is loading/fetched/error. And display something accordingly.

Rémi Rousselet
  • 256,336
  • 79
  • 519
  • 432
  • Thanks that helped me out a lot. I have a Future that executes the http get and parses the json into a model and I set it up in initState. Everything works great and my model updates and my widgets update. One final question. Once my Future completes I want to schedule it to do the whole thing again after a period of time. Suggestion? – dakamojo Mar 06 '18 at 22:57
  • You can use another future that will periodically call the first one again. That future would use `Future.doWhile` and `await new Future.delayed` – Rémi Rousselet Mar 07 '18 at 07:45