Flutter Future:A build function returned nullAndroid - dataSnapshot.getValue() returns null on second call (but not first)(Firebase Unity SDK) Not entering ContinueWith() when called on GetValueAsync()AngularFire2 Query List Get Child ValuesAngular JS don't load value in the scope from function javascriptFirebase transaction returns null and completes without errorFlutter : Bad state: Stream has already been listened toInitialize object to show in my ScaffoldHow to download data from Firebase?Flutter: Question about async function to retrieve Firebase user IDHow to add child to a List in Firebase Realtime Database with a cloud function?

Negative Resistance

Find a stone which is not the lightest one

How to keep bees out of canned beverages?

Scheduling based problem

A strange hotel

Can a stored procedure reference the database in which it is stored?

Does Mathematica have an implementation of the Poisson binomial distribution?

Can I criticise the more senior developers around me for not writing clean code?

A Paper Record is What I Hamper

Check if a string is entirely made of the same substring

Contradiction proof for inequality of P and NP?

Island of Knights, Knaves and Spies

Could moose/elk survive in the Amazon forest?

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

What was Apollo 13's "Little Jolt" after MECO?

How does the mezzoloth's teleportation work?

My bank got bought out, am I now going to have to start filing tax returns in a different state?

Why must Chinese maps be obfuscated?

How long after the last departure shall the airport stay open for an emergency return?

How exactly does Hawking radiation decrease the mass of black holes?

Older movie/show about humans on derelict alien warship which refuels by passing through a star

Was Dennis Ritchie being too modest in this quote about C and Pascal?

How can I wire a 9-position switch so that each position turns on one more LED than the one before?

What is this word supposed to be?



Flutter Future:A build function returned null


Android - dataSnapshot.getValue() returns null on second call (but not first)(Firebase Unity SDK) Not entering ContinueWith() when called on GetValueAsync()AngularFire2 Query List Get Child ValuesAngular JS don't load value in the scope from function javascriptFirebase transaction returns null and completes without errorFlutter : Bad state: Stream has already been listened toInitialize object to show in my ScaffoldHow to download data from Firebase?Flutter: Question about async function to retrieve Firebase user IDHow to add child to a List in Firebase Realtime Database with a cloud function?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I want to retrieve data from firebase to future builder.I use this function for that.



Future getAllData() async 
ReseviorDataModel resModel;
DatabaseReference ref = FirebaseDatabase.instance.reference();
DataSnapshot childed =await
ref.child("Reservoir/$widget.placeName").once();
Map<dynamic, dynamic> values;
values = childed.value;
resModel = ReseviorDataModel.customConstrcutor(values["sensor1"],
values["sensor2"], values["sensor3"]);
return resModel;



I invoke this function inside my future builder.



 child: FutureBuilder(
future: getAllData(),
builder: (context, snapshot)
Center(child: Text(snapshot.data));



but it keeps throwing this "A build function returned null." error .i cant figure out what is the problem here










share|improve this question

















  • 1





    replace Center with return Center

    – pskink
    Mar 9 at 7:22











  • it worked. highly appreciated

    – NicoleZ
    Mar 9 at 7:26











  • sure, your welcome

    – pskink
    Mar 9 at 7:26






  • 1





    @pskink Please write it down as answer otherwise someone else may come up and write the same thing down.

    – CopsOnRoad
    Mar 9 at 7:50

















1















I want to retrieve data from firebase to future builder.I use this function for that.



Future getAllData() async 
ReseviorDataModel resModel;
DatabaseReference ref = FirebaseDatabase.instance.reference();
DataSnapshot childed =await
ref.child("Reservoir/$widget.placeName").once();
Map<dynamic, dynamic> values;
values = childed.value;
resModel = ReseviorDataModel.customConstrcutor(values["sensor1"],
values["sensor2"], values["sensor3"]);
return resModel;



I invoke this function inside my future builder.



 child: FutureBuilder(
future: getAllData(),
builder: (context, snapshot)
Center(child: Text(snapshot.data));



but it keeps throwing this "A build function returned null." error .i cant figure out what is the problem here










share|improve this question

















  • 1





    replace Center with return Center

    – pskink
    Mar 9 at 7:22











  • it worked. highly appreciated

    – NicoleZ
    Mar 9 at 7:26











  • sure, your welcome

    – pskink
    Mar 9 at 7:26






  • 1





    @pskink Please write it down as answer otherwise someone else may come up and write the same thing down.

    – CopsOnRoad
    Mar 9 at 7:50













1












1








1








I want to retrieve data from firebase to future builder.I use this function for that.



Future getAllData() async 
ReseviorDataModel resModel;
DatabaseReference ref = FirebaseDatabase.instance.reference();
DataSnapshot childed =await
ref.child("Reservoir/$widget.placeName").once();
Map<dynamic, dynamic> values;
values = childed.value;
resModel = ReseviorDataModel.customConstrcutor(values["sensor1"],
values["sensor2"], values["sensor3"]);
return resModel;



I invoke this function inside my future builder.



 child: FutureBuilder(
future: getAllData(),
builder: (context, snapshot)
Center(child: Text(snapshot.data));



but it keeps throwing this "A build function returned null." error .i cant figure out what is the problem here










share|improve this question














I want to retrieve data from firebase to future builder.I use this function for that.



Future getAllData() async 
ReseviorDataModel resModel;
DatabaseReference ref = FirebaseDatabase.instance.reference();
DataSnapshot childed =await
ref.child("Reservoir/$widget.placeName").once();
Map<dynamic, dynamic> values;
values = childed.value;
resModel = ReseviorDataModel.customConstrcutor(values["sensor1"],
values["sensor2"], values["sensor3"]);
return resModel;



I invoke this function inside my future builder.



 child: FutureBuilder(
future: getAllData(),
builder: (context, snapshot)
Center(child: Text(snapshot.data));



but it keeps throwing this "A build function returned null." error .i cant figure out what is the problem here







firebase firebase-realtime-database flutter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 9 at 7:19









NicoleZNicoleZ

529




529







  • 1





    replace Center with return Center

    – pskink
    Mar 9 at 7:22











  • it worked. highly appreciated

    – NicoleZ
    Mar 9 at 7:26











  • sure, your welcome

    – pskink
    Mar 9 at 7:26






  • 1





    @pskink Please write it down as answer otherwise someone else may come up and write the same thing down.

    – CopsOnRoad
    Mar 9 at 7:50












  • 1





    replace Center with return Center

    – pskink
    Mar 9 at 7:22











  • it worked. highly appreciated

    – NicoleZ
    Mar 9 at 7:26











  • sure, your welcome

    – pskink
    Mar 9 at 7:26






  • 1





    @pskink Please write it down as answer otherwise someone else may come up and write the same thing down.

    – CopsOnRoad
    Mar 9 at 7:50







1




1





replace Center with return Center

– pskink
Mar 9 at 7:22





replace Center with return Center

– pskink
Mar 9 at 7:22













it worked. highly appreciated

– NicoleZ
Mar 9 at 7:26





it worked. highly appreciated

– NicoleZ
Mar 9 at 7:26













sure, your welcome

– pskink
Mar 9 at 7:26





sure, your welcome

– pskink
Mar 9 at 7:26




1




1





@pskink Please write it down as answer otherwise someone else may come up and write the same thing down.

– CopsOnRoad
Mar 9 at 7:50





@pskink Please write it down as answer otherwise someone else may come up and write the same thing down.

– CopsOnRoad
Mar 9 at 7:50












1 Answer
1






active

oldest

votes


















1














To clear things up here, your builder always has to return a widget to display. You can never return null, as the error message describes.



The problem in this case was that the OP didn't return anything from the builder, so just adding a return worked out fine.



Some things to keep in mind when using FutureBuilder. Always check the snapshot.hasData property and return a UI accordingly. This will prevent cases where the snapshot.data is null causing a new error to be thrown in your Widget taking in the null.



Example:



child: FutureBuilder(
future: getAllData(),
builder: (context, snapshot)
if(!snapshot.hasData)
// show loading while waiting for real data
return CircularProgressIndicator();


return Center(child: Text(snapshot.data));






share|improve this answer























    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/3.0/"u003ecc by-sa 3.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%2f55074996%2fflutter-futurea-build-function-returned-null%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    To clear things up here, your builder always has to return a widget to display. You can never return null, as the error message describes.



    The problem in this case was that the OP didn't return anything from the builder, so just adding a return worked out fine.



    Some things to keep in mind when using FutureBuilder. Always check the snapshot.hasData property and return a UI accordingly. This will prevent cases where the snapshot.data is null causing a new error to be thrown in your Widget taking in the null.



    Example:



    child: FutureBuilder(
    future: getAllData(),
    builder: (context, snapshot)
    if(!snapshot.hasData)
    // show loading while waiting for real data
    return CircularProgressIndicator();


    return Center(child: Text(snapshot.data));






    share|improve this answer



























      1














      To clear things up here, your builder always has to return a widget to display. You can never return null, as the error message describes.



      The problem in this case was that the OP didn't return anything from the builder, so just adding a return worked out fine.



      Some things to keep in mind when using FutureBuilder. Always check the snapshot.hasData property and return a UI accordingly. This will prevent cases where the snapshot.data is null causing a new error to be thrown in your Widget taking in the null.



      Example:



      child: FutureBuilder(
      future: getAllData(),
      builder: (context, snapshot)
      if(!snapshot.hasData)
      // show loading while waiting for real data
      return CircularProgressIndicator();


      return Center(child: Text(snapshot.data));






      share|improve this answer

























        1












        1








        1







        To clear things up here, your builder always has to return a widget to display. You can never return null, as the error message describes.



        The problem in this case was that the OP didn't return anything from the builder, so just adding a return worked out fine.



        Some things to keep in mind when using FutureBuilder. Always check the snapshot.hasData property and return a UI accordingly. This will prevent cases where the snapshot.data is null causing a new error to be thrown in your Widget taking in the null.



        Example:



        child: FutureBuilder(
        future: getAllData(),
        builder: (context, snapshot)
        if(!snapshot.hasData)
        // show loading while waiting for real data
        return CircularProgressIndicator();


        return Center(child: Text(snapshot.data));






        share|improve this answer













        To clear things up here, your builder always has to return a widget to display. You can never return null, as the error message describes.



        The problem in this case was that the OP didn't return anything from the builder, so just adding a return worked out fine.



        Some things to keep in mind when using FutureBuilder. Always check the snapshot.hasData property and return a UI accordingly. This will prevent cases where the snapshot.data is null causing a new error to be thrown in your Widget taking in the null.



        Example:



        child: FutureBuilder(
        future: getAllData(),
        builder: (context, snapshot)
        if(!snapshot.hasData)
        // show loading while waiting for real data
        return CircularProgressIndicator();


        return Center(child: Text(snapshot.data));







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 9 at 9:35









        Filled StacksFilled Stacks

        1,1441917




        1,1441917





























            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%2f55074996%2fflutter-futurea-build-function-returned-null%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

            AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

            Алба-Юлія

            Захаров Федір Захарович