Turning navigation routes into asynchronous functions
In this recipe, you will see how to leverage Futures using Navigator
to transform a Route
into an async
function: you will push a new screen in the app and then await the route to return some data and update the original screen.
The steps we will follow are these:
- Adding an
ElevatedButton
that will launch the second screen. - On the second screen, we will make the user choose a color.
- Once the color is chosen, the second screen will update the background color on the first screen.
Here, you can see a screenshot of the first screen:
And here, the second screen, which allows choosing a color with three ElevatedButtons:
Getting ready
- If you followed along with any of the previous recipes in this chapter, you'll only need to edit the existing project. Otherwise, create a new app with the starting code available at https://github.com/PacktPublishing/Flutter-Cookbook/tree/master/chapter_07.
How to do it...
We will begin by...