Search code examples
flutterdartfutureflutter-futurebuilder

Why FutureBuilder never reload data when it changed in Flutter


I try to upload an image inside FutuerBuilder in flutter but nothing happen to the UI. I have to leave the current page and enter it again to see changes. That is happenn in uploading the image, but when I delete it the FutuerBuilder updated directly.

FutureBuilder(
      future: future,
      initialData: const [],
      builder: (context, imagesSnapshot) {
     if (imagesSnapshot.data == null) {
         return const Center(
             child: Text("..."),
        );
     }else if (imagesSnapshot.hasError){
        return const Center(child: Icon(Icons.error),);
         } else {
           final images = imagesSnapshot.data!
               .where((element)=> element["collectionId"] == collections[i].collectionId);
    } 
  }
)

I tried to use setState to re-build the page but it did not. Also I tried to load the data from the server but nothing happen.


Solution

  • I just removed initState and I put the future directly inside the FutureBuilder. and I reload the data agin after uploading has done, and that worked.