How to deal with unwanted widget build?

For various reasons, sometimes the build method of my widgets is called again.

I know that it happens because a parent updated. But this causes undesired effects.
A typical situation where it causes problems is when using FutureBuilder this way:

@override
Widget build(BuildContext context) {
  return FutureBuilder(
    future: httpCall(),
    builder: (context, snapshot) {
      // create some layout here
    },
  );
}

In this example, if the build method were to be called again, it would trigger another HTTP request. Which is undesired.

Considering this, how to deal with the unwanted build? Is there any way to prevent a build call?

6 Answers
6

Leave a Comment