0

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

1 Answers1

0

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.

Jay Mungara
  • 6,663
  • 2
  • 27
  • 49
  • thank you, yeah the build function was called multiple times causing the same behavior for other widgets, i will try to fix that . – Kane David May 09 '21 at 12:58
  • i still cant figure the problem, i call this screen from a launcher one that check connection but i don't know why it call the home screen multiple times, i added the missing code. – Kane David May 09 '21 at 13:34
  • @KaneDavid If you add print logs for all your methods or debug each point of execution will help you to figure out why your "Build" method or "mainWidget()" is being called multiple times. – Jay Mungara May 10 '21 at 03:36