Load data with FutureBuilder
Show a loading spinner, then the data, or an error, with FutureBuilder.
intermediateDart / Flutter· Flutter & Dart
The task
loadQuote() pretends to load a quote from the internet (it waits 1 second). Build a QuoteScreen that:
- shows a CircularProgressIndicator while loading,
- shows the quote when it arrives,
- shows "Couldn't load the quote." if it fails,
- has a Reload button that loads a new one.
Use FutureBuilder. Start the future in initState, not in build.
What you'll build
The finished app screen, as a web preview (yours will run on a phone or emulator). Try it, then build it below.