FutureBuilder keeps Firing the Future method

Issue

I get the data from http request, then i load it using futureBuilder, the problem is that it keeps calling the future method even if i set a variable with the future method in ‘initState ()’, but it still keeps calling it multiple times, i also tried the AsyncMemoizer too but no good, here is the code:
my FutureBuilder

future method and iniState

Http request method

home screen build

I hope someone help me with the solution.

here is the rest of the code:

launcher screen build

connection method

Solution

Futurebuilder widget depends on future. As, you haven’t shown your build method I can’t predict surely. But, I think You have called mainWidget() Future from your Build method. So, whenever you’re build method gets re-rendered or called Your mainWidget() also get called and so does your FutureBuilder Widget and its future.

So, you will need to make sure that your mainWidget() does not gets called many times. Or manage your build widget in a way that your FutureBuilder doesn’t need to be called more than once.

To check simply add a print log in your mainWidget() that it is called multiple time or not.

This will solve your issue I think.

Answered By – Jay Mungara

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *