Flutter take action based on snapshot of Future

Posted by Pinki | Updated on

Flutter take action based on snapshot of Future. You can check for a statusCode inside your Async method, and use setState to erase the value of the token based on the statusCode value; otherwise, if the connection is authorized, return your desired data. Now, in your FutureBuilder , check if the you snapshot is null to show a SignIn() page instead.

For example, your method that handles the http requests might look something like:

Then you can have a FutureBuilder like this:

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers