Welcome to How do I series…
In this blog post, we’ll learn, how to create a build a widget, with multiple Futures in Flutter
Imagine a scenario where we need to depend more than one condition. Let’s consider the following scenario.
To achieve this, we will use
- a function that returns a
Future
to determine if the app is opened for first time. - a function that returns a
Future
to determine if the user session is active.
Let’s see using multiple futures in flutter within single widget. For this, we will use Future.wait()
, that waits for multiple futures to complete and collects their results. The value of the returned future will be a list of all the values that were produced in the order that the futures are provided by iterating [futures].
In our example, we will useFuture.wait([_checkFirstTimeInstall(), _getAuthSession()])
Future.wait([_checkFirstTimeInstall(), _getAuthSession()])
Now, the complete widget code would be like this
That’s it. You are done.
Please Clap and Share if you like it. Follow, to receive occasional updates.