Flutter Future Builder Example
The problem of how to execute an async function before the UI builds was vexing to me.
The answer turned out to be quite simple. Use the FutureBuilder option. Using this option itself can see vexing at first, but it is also simple, once you know how.
- Specify the async function to execute before the build. In the below example, the function is called _doWork().
- Set the name of the variable that can be tested to determine if work is completed. In the below case “canbeanyname”. It can be any name and does not have to be previously defined.
3. Write the _doWork() function. In this case, building a list of images that have network addresses and will be retrieved asynchronously.
4. Complete the build function
Full working code can be found here: