Skip to content

When you call an API, do you ever call it twice? #3192

Answered by mark8044
hongmono asked this question in Q&A
Discussion options

You must be logged in to vote

I can tell you for me its happened all the time.

In my case it was ALWAYS because of rebuilds. Either a FutureBuilder would rebuild, or a riverpod watch would cause a rebuild, or I would sneeze and I would get a rebuild.

I managed to solve them all by paying attention to minimizing rebuilds.

Using riverpod .select was a god-send. Look into it, it can save you not of headaches.

When I couldn't solve the cause of the rebuild, then I resort to creating a variable for example bool didIcalltheAPIyet = false and then once the API is called, I would switch that to true and block any further calls that way.

bool didIcalltheAPIyet = false;

if (didIcalltheAPIyet == false)
{
   didIcalltheAPIyet = …

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@hongmono
Comment options

@AhmedLSayed9
Comment options

@zamiramir
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by hongmono
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants