Flutter — Using Multiple Futures in single widget

Sravan
1 min readMar 14, 2021

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.

Flowchart
Flow chart

To achieve this, we will use

  1. a function that returns aFuture to determine if the app is opened for first time.
  2. 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.

--

--

Sravan

Hi there, I’m Sravan. I am an influential and diligent professional with rich experience in Development.