How to inform FutureBuilder that database was updated?Flutter - How to pass user data to all viewsTabBar setting setting state of tabviewsCalling scopedModel from initState in flutterHow to make sure UI gets updated in flutter before a long task completes on the main threadHow to query firestore document inside streambuilder and update the listviewtype 'Future<int>' is not a subtype of type 'int' with FlutterFlutter: Firebase auth and Firestore snapshot streamAsync function not being called on page creationHow to retrieve specific user details from firestore with flutterWhat's the accepted pattern for global, updatable data?

Booting Ubuntu from USB drive on MSI motherboard -- EVERYTHING fails

Could Boris Johnson face criminal charges for illegally proroguing Parliament?

Citing CPLEX 12.9

How can I find places to store/land a private airplane?

Why is there such a singular place for bird watching?

Sending mail to the Professor for PhD, after seeing his tweet

What powers or limits devil promotion?

Writing about real people - not giving offence

What did the Federation give the Prophets in exchange for access to the wormhole in DS9?

Young adult short story book with one story where a woman finds a walrus suit and becomes a walrus

Does it require less energy to reach the Sun from Pluto's orbit than from Earth's orbit?

As a team leader is it appropriate to bring in fundraiser candy?

Everyone Gets a Window Seat

How do we know Nemesis is not a black hole (or neutron star)?

How to "Start as close to the end as possible", and why to do so?

Where does the image of a data connector as a sharp metal spike originate from?

How to say "respectively" in German when listing (enumerating) things

Is there a way to make an animal companion able to read a language?

Why does the Pilatus PC-24 have such a large "Wing Support"?

Quote to show students don't have to fear making mistakes

Airport Security - advanced check, 4th amendment breach

Using RECURSIVE in Virtual Layer

Ĉi tie or ĉi-tie? Why do people sometimes hyphenate ĉi tie?

Job interview by video at home and privacy concerns



How to inform FutureBuilder that database was updated?


Flutter - How to pass user data to all viewsTabBar setting setting state of tabviewsCalling scopedModel from initState in flutterHow to make sure UI gets updated in flutter before a long task completes on the main threadHow to query firestore document inside streambuilder and update the listviewtype 'Future<int>' is not a subtype of type 'int' with FlutterFlutter: Firebase auth and Firestore snapshot streamAsync function not being called on page creationHow to retrieve specific user details from firestore with flutterWhat's the accepted pattern for global, updatable data?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









0















I have a group profile page, where a user can change the description of a group. He clicks on the description, gets on a new screen and saves it to Firestore. He then get's back via Navigator.pop(context) to the group profile page which lists all elements via FutureBuilder.



First, I had the database request for my FutureBuilder inside the main build method (directly inside future builder 'future: request') which was working but I learnt it is wrong. But now I have to wait for a rebuild to see changes. How do I tell FutureBuilder that there is a data update?



I am loading Firestore data as follows within the group profile page:



Future<DocumentSnapshot> _future;

@override
void initState()
super.initState();
_getFiretoreData();


Future<void> _getFiretoreData() async
setState(()

this._future = Firestore.instance
.collection('users')
.document(globals.userId.toString())
.get(););



The FutureBuilder is inside the main build method and gets the 'already loaded' future like this:



FutureBuilder(future: _future, ...)


Now I would like to tell him: a change happened to _future, please rebuild ;-).










share|improve this question






























    0















    I have a group profile page, where a user can change the description of a group. He clicks on the description, gets on a new screen and saves it to Firestore. He then get's back via Navigator.pop(context) to the group profile page which lists all elements via FutureBuilder.



    First, I had the database request for my FutureBuilder inside the main build method (directly inside future builder 'future: request') which was working but I learnt it is wrong. But now I have to wait for a rebuild to see changes. How do I tell FutureBuilder that there is a data update?



    I am loading Firestore data as follows within the group profile page:



    Future<DocumentSnapshot> _future;

    @override
    void initState()
    super.initState();
    _getFiretoreData();


    Future<void> _getFiretoreData() async
    setState(()

    this._future = Firestore.instance
    .collection('users')
    .document(globals.userId.toString())
    .get(););



    The FutureBuilder is inside the main build method and gets the 'already loaded' future like this:



    FutureBuilder(future: _future, ...)


    Now I would like to tell him: a change happened to _future, please rebuild ;-).










    share|improve this question


























      0












      0








      0








      I have a group profile page, where a user can change the description of a group. He clicks on the description, gets on a new screen and saves it to Firestore. He then get's back via Navigator.pop(context) to the group profile page which lists all elements via FutureBuilder.



      First, I had the database request for my FutureBuilder inside the main build method (directly inside future builder 'future: request') which was working but I learnt it is wrong. But now I have to wait for a rebuild to see changes. How do I tell FutureBuilder that there is a data update?



      I am loading Firestore data as follows within the group profile page:



      Future<DocumentSnapshot> _future;

      @override
      void initState()
      super.initState();
      _getFiretoreData();


      Future<void> _getFiretoreData() async
      setState(()

      this._future = Firestore.instance
      .collection('users')
      .document(globals.userId.toString())
      .get(););



      The FutureBuilder is inside the main build method and gets the 'already loaded' future like this:



      FutureBuilder(future: _future, ...)


      Now I would like to tell him: a change happened to _future, please rebuild ;-).










      share|improve this question














      I have a group profile page, where a user can change the description of a group. He clicks on the description, gets on a new screen and saves it to Firestore. He then get's back via Navigator.pop(context) to the group profile page which lists all elements via FutureBuilder.



      First, I had the database request for my FutureBuilder inside the main build method (directly inside future builder 'future: request') which was working but I learnt it is wrong. But now I have to wait for a rebuild to see changes. How do I tell FutureBuilder that there is a data update?



      I am loading Firestore data as follows within the group profile page:



      Future<DocumentSnapshot> _future;

      @override
      void initState()
      super.initState();
      _getFiretoreData();


      Future<void> _getFiretoreData() async
      setState(()

      this._future = Firestore.instance
      .collection('users')
      .document(globals.userId.toString())
      .get(););



      The FutureBuilder is inside the main build method and gets the 'already loaded' future like this:



      FutureBuilder(future: _future, ...)


      Now I would like to tell him: a change happened to _future, please rebuild ;-).







      flutter flutter-layout






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 21:14









      user3532201user3532201

      911 silver badge11 bronze badges




      911 silver badge11 bronze badges

























          5 Answers
          5






          active

          oldest

          votes


















          2
















          Ok, I managed it like this (which took me only a few lines of code). Leave the code as it is and get a true callback from the navigator to know that there was a change on the second page:



          // check if second page callback is true
          bool _changed = await Navigator.push(
          context,
          MaterialPageRoute(
          builder: (context) =>
          ProfileUpdate(userId: globals.userId.toString())),
          );
          // if it's true, reload future data
          _changed ? _getFiretoreData() : Container();


          On the second page give the save button a Navigator.pop(context, true).






          share|improve this answer
































            0
















            Why don't you use Stream builder instead of Future builder?



            StreamBuilder(stream: _future, ...)


            You can change the variable name to _stream for clarity.






            share|improve this answer

























            • I am using StreamBuilder within my chat. I thought when I am only receiving 'onetime' data (which is only updated when saved), FutureBuilder is more cost efficient.

              – user3532201
              Mar 29 at 2:59


















            0
















            i would advice you not to use future builder in this situation and use future.then() in an async function and after you get your data update the build without using future builder..!



            Future getData() async 
            //here you can call the function and handle the output(return value) as result
            getFiretoreData().then((result)
            // print(result);
            setState(()
            //handle your result here.
            //update build here.
            );
            );






            share|improve this answer

























            • Any idea how I can update the build when I saved data on another screen?

              – user3532201
              Mar 29 at 12:21











            • do you mean you are saving data on a screen In an async method? and then you want to be informed on another page correct me if i am wrong.

              – youssef ali
              Mar 29 at 14:15






            • 1





              I am loading the async future via initState. But this future is already 'delivered', so FutureBuilder only updates _getFiretoreData() is run again. But I managed to get it working - have a look at my answer if you're interested ;-).

              – user3532201
              Mar 29 at 14:20











            • actually i knew this i just didnt think you to go to a new page except now XD

              – youssef ali
              Mar 29 at 14:31











            • one question do you go to a complete new widget to get the data only ?

              – youssef ali
              Mar 29 at 16:16


















            -1
















            How about this?



            @override
            Widget build(BuildContext context)
            if (_future == null)
            // show loading indicator while waiting for data
            return Center(child: CircularProgressIndicator());
            else
            return YourWidget();







            share|improve this answer
































              -1
















              You do not need to set any state. You just need to return your collection of users in your GetFirestoreData method.



              Future<TypeYouReturning> _getFirestoreData() async
              return Firestore.instance
              .collection('users')
              .document(globals.userId.toString())
              .get();




              Inside your FutureBuilder widget you can set it up something like Theo recommended, I would do something like this



              return FutureBuilder(
              future: _getFirestoreData(),
              builder: (context, AsyncSnapshot<TypeYouReturning> snapshot)
              if (!snapshot.hasData)
              return Center(
              child: CircularProgressIndicator(),
              );
              else
              if (snapshot.data.length == 0)
              return Text("No available data just yet");

              return Container();//This should be the desire widget you want the user to see

              ,
              );





              share|improve this answer




















              • 1





                I think I was not clear enough. The documentation says: "The future must have been obtained earlier, e.g. during State.initState, State.didUpdateConfig, or State.didChangeDependencies. It must not be created during the State.build or StatelessWidget.build method call when constructing the FutureBuilder. If the future is created at the same time as the FutureBuilder, then every time the FutureBuilder's parent is rebuilt, the asynchronous task will be restarted." So the future is loaded via initstate. But then it is 'finished' - data change does not rebuild FutureBuilder. So how can I notify it?

                – user3532201
                Mar 29 at 1:04











              • I have learned it from here. youtube.com/watch?v=rfagvy5xCW0 check 1:03:00 in the video. They teach you the exact same thing I have just answered. If you still think my answered is wrong leave the downvote, if not please revert it. Hope it clarifies things for you.

                – Matias
                Mar 29 at 13:56






              • 1





                I did not downvote your answer - I never do it because I appreciate help here. I figured out a way for my issue. Have a look at my reply if you're interested.

                – user3532201
                Mar 29 at 14:10













              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );














              draft saved

              draft discarded
















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406942%2fhow-to-inform-futurebuilder-that-database-was-updated%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              5 Answers
              5






              active

              oldest

              votes








              5 Answers
              5






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2
















              Ok, I managed it like this (which took me only a few lines of code). Leave the code as it is and get a true callback from the navigator to know that there was a change on the second page:



              // check if second page callback is true
              bool _changed = await Navigator.push(
              context,
              MaterialPageRoute(
              builder: (context) =>
              ProfileUpdate(userId: globals.userId.toString())),
              );
              // if it's true, reload future data
              _changed ? _getFiretoreData() : Container();


              On the second page give the save button a Navigator.pop(context, true).






              share|improve this answer





























                2
















                Ok, I managed it like this (which took me only a few lines of code). Leave the code as it is and get a true callback from the navigator to know that there was a change on the second page:



                // check if second page callback is true
                bool _changed = await Navigator.push(
                context,
                MaterialPageRoute(
                builder: (context) =>
                ProfileUpdate(userId: globals.userId.toString())),
                );
                // if it's true, reload future data
                _changed ? _getFiretoreData() : Container();


                On the second page give the save button a Navigator.pop(context, true).






                share|improve this answer



























                  2














                  2










                  2









                  Ok, I managed it like this (which took me only a few lines of code). Leave the code as it is and get a true callback from the navigator to know that there was a change on the second page:



                  // check if second page callback is true
                  bool _changed = await Navigator.push(
                  context,
                  MaterialPageRoute(
                  builder: (context) =>
                  ProfileUpdate(userId: globals.userId.toString())),
                  );
                  // if it's true, reload future data
                  _changed ? _getFiretoreData() : Container();


                  On the second page give the save button a Navigator.pop(context, true).






                  share|improve this answer













                  Ok, I managed it like this (which took me only a few lines of code). Leave the code as it is and get a true callback from the navigator to know that there was a change on the second page:



                  // check if second page callback is true
                  bool _changed = await Navigator.push(
                  context,
                  MaterialPageRoute(
                  builder: (context) =>
                  ProfileUpdate(userId: globals.userId.toString())),
                  );
                  // if it's true, reload future data
                  _changed ? _getFiretoreData() : Container();


                  On the second page give the save button a Navigator.pop(context, true).







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 29 at 14:14









                  user3532201user3532201

                  911 silver badge11 bronze badges




                  911 silver badge11 bronze badges


























                      0
















                      Why don't you use Stream builder instead of Future builder?



                      StreamBuilder(stream: _future, ...)


                      You can change the variable name to _stream for clarity.






                      share|improve this answer

























                      • I am using StreamBuilder within my chat. I thought when I am only receiving 'onetime' data (which is only updated when saved), FutureBuilder is more cost efficient.

                        – user3532201
                        Mar 29 at 2:59















                      0
















                      Why don't you use Stream builder instead of Future builder?



                      StreamBuilder(stream: _future, ...)


                      You can change the variable name to _stream for clarity.






                      share|improve this answer

























                      • I am using StreamBuilder within my chat. I thought when I am only receiving 'onetime' data (which is only updated when saved), FutureBuilder is more cost efficient.

                        – user3532201
                        Mar 29 at 2:59













                      0














                      0










                      0









                      Why don't you use Stream builder instead of Future builder?



                      StreamBuilder(stream: _future, ...)


                      You can change the variable name to _stream for clarity.






                      share|improve this answer













                      Why don't you use Stream builder instead of Future builder?



                      StreamBuilder(stream: _future, ...)


                      You can change the variable name to _stream for clarity.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Mar 29 at 2:02









                      mirkancalmirkancal

                      8422 gold badges5 silver badges21 bronze badges




                      8422 gold badges5 silver badges21 bronze badges















                      • I am using StreamBuilder within my chat. I thought when I am only receiving 'onetime' data (which is only updated when saved), FutureBuilder is more cost efficient.

                        – user3532201
                        Mar 29 at 2:59

















                      • I am using StreamBuilder within my chat. I thought when I am only receiving 'onetime' data (which is only updated when saved), FutureBuilder is more cost efficient.

                        – user3532201
                        Mar 29 at 2:59
















                      I am using StreamBuilder within my chat. I thought when I am only receiving 'onetime' data (which is only updated when saved), FutureBuilder is more cost efficient.

                      – user3532201
                      Mar 29 at 2:59





                      I am using StreamBuilder within my chat. I thought when I am only receiving 'onetime' data (which is only updated when saved), FutureBuilder is more cost efficient.

                      – user3532201
                      Mar 29 at 2:59











                      0
















                      i would advice you not to use future builder in this situation and use future.then() in an async function and after you get your data update the build without using future builder..!



                      Future getData() async 
                      //here you can call the function and handle the output(return value) as result
                      getFiretoreData().then((result)
                      // print(result);
                      setState(()
                      //handle your result here.
                      //update build here.
                      );
                      );






                      share|improve this answer

























                      • Any idea how I can update the build when I saved data on another screen?

                        – user3532201
                        Mar 29 at 12:21











                      • do you mean you are saving data on a screen In an async method? and then you want to be informed on another page correct me if i am wrong.

                        – youssef ali
                        Mar 29 at 14:15






                      • 1





                        I am loading the async future via initState. But this future is already 'delivered', so FutureBuilder only updates _getFiretoreData() is run again. But I managed to get it working - have a look at my answer if you're interested ;-).

                        – user3532201
                        Mar 29 at 14:20











                      • actually i knew this i just didnt think you to go to a new page except now XD

                        – youssef ali
                        Mar 29 at 14:31











                      • one question do you go to a complete new widget to get the data only ?

                        – youssef ali
                        Mar 29 at 16:16















                      0
















                      i would advice you not to use future builder in this situation and use future.then() in an async function and after you get your data update the build without using future builder..!



                      Future getData() async 
                      //here you can call the function and handle the output(return value) as result
                      getFiretoreData().then((result)
                      // print(result);
                      setState(()
                      //handle your result here.
                      //update build here.
                      );
                      );






                      share|improve this answer

























                      • Any idea how I can update the build when I saved data on another screen?

                        – user3532201
                        Mar 29 at 12:21











                      • do you mean you are saving data on a screen In an async method? and then you want to be informed on another page correct me if i am wrong.

                        – youssef ali
                        Mar 29 at 14:15






                      • 1





                        I am loading the async future via initState. But this future is already 'delivered', so FutureBuilder only updates _getFiretoreData() is run again. But I managed to get it working - have a look at my answer if you're interested ;-).

                        – user3532201
                        Mar 29 at 14:20











                      • actually i knew this i just didnt think you to go to a new page except now XD

                        – youssef ali
                        Mar 29 at 14:31











                      • one question do you go to a complete new widget to get the data only ?

                        – youssef ali
                        Mar 29 at 16:16













                      0














                      0










                      0









                      i would advice you not to use future builder in this situation and use future.then() in an async function and after you get your data update the build without using future builder..!



                      Future getData() async 
                      //here you can call the function and handle the output(return value) as result
                      getFiretoreData().then((result)
                      // print(result);
                      setState(()
                      //handle your result here.
                      //update build here.
                      );
                      );






                      share|improve this answer













                      i would advice you not to use future builder in this situation and use future.then() in an async function and after you get your data update the build without using future builder..!



                      Future getData() async 
                      //here you can call the function and handle the output(return value) as result
                      getFiretoreData().then((result)
                      // print(result);
                      setState(()
                      //handle your result here.
                      //update build here.
                      );
                      );







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Mar 29 at 9:42









                      youssef aliyoussef ali

                      1061 silver badge6 bronze badges




                      1061 silver badge6 bronze badges















                      • Any idea how I can update the build when I saved data on another screen?

                        – user3532201
                        Mar 29 at 12:21











                      • do you mean you are saving data on a screen In an async method? and then you want to be informed on another page correct me if i am wrong.

                        – youssef ali
                        Mar 29 at 14:15






                      • 1





                        I am loading the async future via initState. But this future is already 'delivered', so FutureBuilder only updates _getFiretoreData() is run again. But I managed to get it working - have a look at my answer if you're interested ;-).

                        – user3532201
                        Mar 29 at 14:20











                      • actually i knew this i just didnt think you to go to a new page except now XD

                        – youssef ali
                        Mar 29 at 14:31











                      • one question do you go to a complete new widget to get the data only ?

                        – youssef ali
                        Mar 29 at 16:16

















                      • Any idea how I can update the build when I saved data on another screen?

                        – user3532201
                        Mar 29 at 12:21











                      • do you mean you are saving data on a screen In an async method? and then you want to be informed on another page correct me if i am wrong.

                        – youssef ali
                        Mar 29 at 14:15






                      • 1





                        I am loading the async future via initState. But this future is already 'delivered', so FutureBuilder only updates _getFiretoreData() is run again. But I managed to get it working - have a look at my answer if you're interested ;-).

                        – user3532201
                        Mar 29 at 14:20











                      • actually i knew this i just didnt think you to go to a new page except now XD

                        – youssef ali
                        Mar 29 at 14:31











                      • one question do you go to a complete new widget to get the data only ?

                        – youssef ali
                        Mar 29 at 16:16
















                      Any idea how I can update the build when I saved data on another screen?

                      – user3532201
                      Mar 29 at 12:21





                      Any idea how I can update the build when I saved data on another screen?

                      – user3532201
                      Mar 29 at 12:21













                      do you mean you are saving data on a screen In an async method? and then you want to be informed on another page correct me if i am wrong.

                      – youssef ali
                      Mar 29 at 14:15





                      do you mean you are saving data on a screen In an async method? and then you want to be informed on another page correct me if i am wrong.

                      – youssef ali
                      Mar 29 at 14:15




                      1




                      1





                      I am loading the async future via initState. But this future is already 'delivered', so FutureBuilder only updates _getFiretoreData() is run again. But I managed to get it working - have a look at my answer if you're interested ;-).

                      – user3532201
                      Mar 29 at 14:20





                      I am loading the async future via initState. But this future is already 'delivered', so FutureBuilder only updates _getFiretoreData() is run again. But I managed to get it working - have a look at my answer if you're interested ;-).

                      – user3532201
                      Mar 29 at 14:20













                      actually i knew this i just didnt think you to go to a new page except now XD

                      – youssef ali
                      Mar 29 at 14:31





                      actually i knew this i just didnt think you to go to a new page except now XD

                      – youssef ali
                      Mar 29 at 14:31













                      one question do you go to a complete new widget to get the data only ?

                      – youssef ali
                      Mar 29 at 16:16





                      one question do you go to a complete new widget to get the data only ?

                      – youssef ali
                      Mar 29 at 16:16











                      -1
















                      How about this?



                      @override
                      Widget build(BuildContext context)
                      if (_future == null)
                      // show loading indicator while waiting for data
                      return Center(child: CircularProgressIndicator());
                      else
                      return YourWidget();







                      share|improve this answer





























                        -1
















                        How about this?



                        @override
                        Widget build(BuildContext context)
                        if (_future == null)
                        // show loading indicator while waiting for data
                        return Center(child: CircularProgressIndicator());
                        else
                        return YourWidget();







                        share|improve this answer



























                          -1














                          -1










                          -1









                          How about this?



                          @override
                          Widget build(BuildContext context)
                          if (_future == null)
                          // show loading indicator while waiting for data
                          return Center(child: CircularProgressIndicator());
                          else
                          return YourWidget();







                          share|improve this answer













                          How about this?



                          @override
                          Widget build(BuildContext context)
                          if (_future == null)
                          // show loading indicator while waiting for data
                          return Center(child: CircularProgressIndicator());
                          else
                          return YourWidget();








                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 28 at 21:48









                          TheoTheo

                          194 bronze badges




                          194 bronze badges
























                              -1
















                              You do not need to set any state. You just need to return your collection of users in your GetFirestoreData method.



                              Future<TypeYouReturning> _getFirestoreData() async
                              return Firestore.instance
                              .collection('users')
                              .document(globals.userId.toString())
                              .get();




                              Inside your FutureBuilder widget you can set it up something like Theo recommended, I would do something like this



                              return FutureBuilder(
                              future: _getFirestoreData(),
                              builder: (context, AsyncSnapshot<TypeYouReturning> snapshot)
                              if (!snapshot.hasData)
                              return Center(
                              child: CircularProgressIndicator(),
                              );
                              else
                              if (snapshot.data.length == 0)
                              return Text("No available data just yet");

                              return Container();//This should be the desire widget you want the user to see

                              ,
                              );





                              share|improve this answer




















                              • 1





                                I think I was not clear enough. The documentation says: "The future must have been obtained earlier, e.g. during State.initState, State.didUpdateConfig, or State.didChangeDependencies. It must not be created during the State.build or StatelessWidget.build method call when constructing the FutureBuilder. If the future is created at the same time as the FutureBuilder, then every time the FutureBuilder's parent is rebuilt, the asynchronous task will be restarted." So the future is loaded via initstate. But then it is 'finished' - data change does not rebuild FutureBuilder. So how can I notify it?

                                – user3532201
                                Mar 29 at 1:04











                              • I have learned it from here. youtube.com/watch?v=rfagvy5xCW0 check 1:03:00 in the video. They teach you the exact same thing I have just answered. If you still think my answered is wrong leave the downvote, if not please revert it. Hope it clarifies things for you.

                                – Matias
                                Mar 29 at 13:56






                              • 1





                                I did not downvote your answer - I never do it because I appreciate help here. I figured out a way for my issue. Have a look at my reply if you're interested.

                                – user3532201
                                Mar 29 at 14:10
















                              -1
















                              You do not need to set any state. You just need to return your collection of users in your GetFirestoreData method.



                              Future<TypeYouReturning> _getFirestoreData() async
                              return Firestore.instance
                              .collection('users')
                              .document(globals.userId.toString())
                              .get();




                              Inside your FutureBuilder widget you can set it up something like Theo recommended, I would do something like this



                              return FutureBuilder(
                              future: _getFirestoreData(),
                              builder: (context, AsyncSnapshot<TypeYouReturning> snapshot)
                              if (!snapshot.hasData)
                              return Center(
                              child: CircularProgressIndicator(),
                              );
                              else
                              if (snapshot.data.length == 0)
                              return Text("No available data just yet");

                              return Container();//This should be the desire widget you want the user to see

                              ,
                              );





                              share|improve this answer




















                              • 1





                                I think I was not clear enough. The documentation says: "The future must have been obtained earlier, e.g. during State.initState, State.didUpdateConfig, or State.didChangeDependencies. It must not be created during the State.build or StatelessWidget.build method call when constructing the FutureBuilder. If the future is created at the same time as the FutureBuilder, then every time the FutureBuilder's parent is rebuilt, the asynchronous task will be restarted." So the future is loaded via initstate. But then it is 'finished' - data change does not rebuild FutureBuilder. So how can I notify it?

                                – user3532201
                                Mar 29 at 1:04











                              • I have learned it from here. youtube.com/watch?v=rfagvy5xCW0 check 1:03:00 in the video. They teach you the exact same thing I have just answered. If you still think my answered is wrong leave the downvote, if not please revert it. Hope it clarifies things for you.

                                – Matias
                                Mar 29 at 13:56






                              • 1





                                I did not downvote your answer - I never do it because I appreciate help here. I figured out a way for my issue. Have a look at my reply if you're interested.

                                – user3532201
                                Mar 29 at 14:10














                              -1














                              -1










                              -1









                              You do not need to set any state. You just need to return your collection of users in your GetFirestoreData method.



                              Future<TypeYouReturning> _getFirestoreData() async
                              return Firestore.instance
                              .collection('users')
                              .document(globals.userId.toString())
                              .get();




                              Inside your FutureBuilder widget you can set it up something like Theo recommended, I would do something like this



                              return FutureBuilder(
                              future: _getFirestoreData(),
                              builder: (context, AsyncSnapshot<TypeYouReturning> snapshot)
                              if (!snapshot.hasData)
                              return Center(
                              child: CircularProgressIndicator(),
                              );
                              else
                              if (snapshot.data.length == 0)
                              return Text("No available data just yet");

                              return Container();//This should be the desire widget you want the user to see

                              ,
                              );





                              share|improve this answer













                              You do not need to set any state. You just need to return your collection of users in your GetFirestoreData method.



                              Future<TypeYouReturning> _getFirestoreData() async
                              return Firestore.instance
                              .collection('users')
                              .document(globals.userId.toString())
                              .get();




                              Inside your FutureBuilder widget you can set it up something like Theo recommended, I would do something like this



                              return FutureBuilder(
                              future: _getFirestoreData(),
                              builder: (context, AsyncSnapshot<TypeYouReturning> snapshot)
                              if (!snapshot.hasData)
                              return Center(
                              child: CircularProgressIndicator(),
                              );
                              else
                              if (snapshot.data.length == 0)
                              return Text("No available data just yet");

                              return Container();//This should be the desire widget you want the user to see

                              ,
                              );






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Mar 28 at 22:29









                              MatiasMatias

                              3914 silver badges15 bronze badges




                              3914 silver badges15 bronze badges










                              • 1





                                I think I was not clear enough. The documentation says: "The future must have been obtained earlier, e.g. during State.initState, State.didUpdateConfig, or State.didChangeDependencies. It must not be created during the State.build or StatelessWidget.build method call when constructing the FutureBuilder. If the future is created at the same time as the FutureBuilder, then every time the FutureBuilder's parent is rebuilt, the asynchronous task will be restarted." So the future is loaded via initstate. But then it is 'finished' - data change does not rebuild FutureBuilder. So how can I notify it?

                                – user3532201
                                Mar 29 at 1:04











                              • I have learned it from here. youtube.com/watch?v=rfagvy5xCW0 check 1:03:00 in the video. They teach you the exact same thing I have just answered. If you still think my answered is wrong leave the downvote, if not please revert it. Hope it clarifies things for you.

                                – Matias
                                Mar 29 at 13:56






                              • 1





                                I did not downvote your answer - I never do it because I appreciate help here. I figured out a way for my issue. Have a look at my reply if you're interested.

                                – user3532201
                                Mar 29 at 14:10













                              • 1





                                I think I was not clear enough. The documentation says: "The future must have been obtained earlier, e.g. during State.initState, State.didUpdateConfig, or State.didChangeDependencies. It must not be created during the State.build or StatelessWidget.build method call when constructing the FutureBuilder. If the future is created at the same time as the FutureBuilder, then every time the FutureBuilder's parent is rebuilt, the asynchronous task will be restarted." So the future is loaded via initstate. But then it is 'finished' - data change does not rebuild FutureBuilder. So how can I notify it?

                                – user3532201
                                Mar 29 at 1:04











                              • I have learned it from here. youtube.com/watch?v=rfagvy5xCW0 check 1:03:00 in the video. They teach you the exact same thing I have just answered. If you still think my answered is wrong leave the downvote, if not please revert it. Hope it clarifies things for you.

                                – Matias
                                Mar 29 at 13:56






                              • 1





                                I did not downvote your answer - I never do it because I appreciate help here. I figured out a way for my issue. Have a look at my reply if you're interested.

                                – user3532201
                                Mar 29 at 14:10








                              1




                              1





                              I think I was not clear enough. The documentation says: "The future must have been obtained earlier, e.g. during State.initState, State.didUpdateConfig, or State.didChangeDependencies. It must not be created during the State.build or StatelessWidget.build method call when constructing the FutureBuilder. If the future is created at the same time as the FutureBuilder, then every time the FutureBuilder's parent is rebuilt, the asynchronous task will be restarted." So the future is loaded via initstate. But then it is 'finished' - data change does not rebuild FutureBuilder. So how can I notify it?

                              – user3532201
                              Mar 29 at 1:04





                              I think I was not clear enough. The documentation says: "The future must have been obtained earlier, e.g. during State.initState, State.didUpdateConfig, or State.didChangeDependencies. It must not be created during the State.build or StatelessWidget.build method call when constructing the FutureBuilder. If the future is created at the same time as the FutureBuilder, then every time the FutureBuilder's parent is rebuilt, the asynchronous task will be restarted." So the future is loaded via initstate. But then it is 'finished' - data change does not rebuild FutureBuilder. So how can I notify it?

                              – user3532201
                              Mar 29 at 1:04













                              I have learned it from here. youtube.com/watch?v=rfagvy5xCW0 check 1:03:00 in the video. They teach you the exact same thing I have just answered. If you still think my answered is wrong leave the downvote, if not please revert it. Hope it clarifies things for you.

                              – Matias
                              Mar 29 at 13:56





                              I have learned it from here. youtube.com/watch?v=rfagvy5xCW0 check 1:03:00 in the video. They teach you the exact same thing I have just answered. If you still think my answered is wrong leave the downvote, if not please revert it. Hope it clarifies things for you.

                              – Matias
                              Mar 29 at 13:56




                              1




                              1





                              I did not downvote your answer - I never do it because I appreciate help here. I figured out a way for my issue. Have a look at my reply if you're interested.

                              – user3532201
                              Mar 29 at 14:10






                              I did not downvote your answer - I never do it because I appreciate help here. I figured out a way for my issue. Have a look at my reply if you're interested.

                              – user3532201
                              Mar 29 at 14:10



















                              draft saved

                              draft discarded















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406942%2fhow-to-inform-futurebuilder-that-database-was-updated%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                              Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript