Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I update the data fetched from a future bilder in Flutter?

In my app I have a screen which contains 3 different future builders, I would like to update the data recovered from a future builder. I tried the setState () method but this updates all 3 future builders on the page, I only need to update one. How can I do ?

My 3 future builders are structured like this:

FutureBuilder(
future: getData(), //Fetch the data
builder:
    (context, AsyncSnapshot snapshot) {
  if (snapshot.connectionState == ConnectionState.done) {
    return Text('${snapshot.data}',
        style: const TextStyle(
            fontSize: 15,
            color: Colors.black));
  } else {
    return const CircularProgressIndicator.adaptive();
  }
})

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want to rebuild just a portion of your screen, you can use StatefulBuilder.
Wrap the single FutureBuilder you want to rebuild with a StatefulBuilder like so:

StatefulBuilder(
 builder: (context, setState) {
  return YourFutureBuilder();
 },
)

If setState is called from inside the StatefulBuilder, only the portion of the screen that is wrapped with the StatefulBuilder will be rebuilt.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading