flutter loop through firebase node that consists of singlenodes and nodes with children












0














I have this piece of code:



  routineExersiceIDsetter() async{
String routineId;
final response = await reference.child(_userId).once();
response.value.forEach((k,v){
if(v["name"] == "First Routine"){
currentRoutineId = k;
routineId = k;
}
});
final response2 = await reference.child(_userId).child(currentRoutineId).once();
response2.value.forEach((k, v){
if(v["name"] == "Day 1"){
currentSchemeId = k;
}

});
}


and this piece of a firebase database



{
"-LBNflaqFEb4DtZiYxnh" : {
"-LBWa99g4yCstUBkDGa7" : {
"name" : "Day 1"
},
"name" : "First Routine"
}
}


the first forEach line works but the second doesn't. Is there a way to make this work or do I need to change my firebase architecture?










share|improve this question
























  • Don't you have to chain the two requests? Queries to Firebase are asynchronous so you should wait the first query resolves to have the value of currentRoutineId and only then you can execute the second query. I don't know how to chain that in dart, so I cannot help you with a full solution.
    – Renaud Tarnec
    May 2 '18 at 17:40












  • @RenaudTarnec I thought I already did that with the await request the perror i get is : type 'String' is not a subtype of type 'int' of 'index'
    – merlijn mac gillavry
    May 2 '18 at 17:42










  • I don't know dart but I have the feeling you are not linking the two awaits. Are you sure currentRoutineId has a correct value in the second 'await'? Can you check with console or log?
    – Renaud Tarnec
    May 2 '18 at 17:45












  • @RenaudTarnec from what I've seen it gets the correct routineid but it still gives an error in the second foreach
    – merlijn mac gillavry
    May 2 '18 at 17:53










  • What do you exactly want to do? Because it seems all the info is under one node
    – Renaud Tarnec
    May 2 '18 at 18:01
















0














I have this piece of code:



  routineExersiceIDsetter() async{
String routineId;
final response = await reference.child(_userId).once();
response.value.forEach((k,v){
if(v["name"] == "First Routine"){
currentRoutineId = k;
routineId = k;
}
});
final response2 = await reference.child(_userId).child(currentRoutineId).once();
response2.value.forEach((k, v){
if(v["name"] == "Day 1"){
currentSchemeId = k;
}

});
}


and this piece of a firebase database



{
"-LBNflaqFEb4DtZiYxnh" : {
"-LBWa99g4yCstUBkDGa7" : {
"name" : "Day 1"
},
"name" : "First Routine"
}
}


the first forEach line works but the second doesn't. Is there a way to make this work or do I need to change my firebase architecture?










share|improve this question
























  • Don't you have to chain the two requests? Queries to Firebase are asynchronous so you should wait the first query resolves to have the value of currentRoutineId and only then you can execute the second query. I don't know how to chain that in dart, so I cannot help you with a full solution.
    – Renaud Tarnec
    May 2 '18 at 17:40












  • @RenaudTarnec I thought I already did that with the await request the perror i get is : type 'String' is not a subtype of type 'int' of 'index'
    – merlijn mac gillavry
    May 2 '18 at 17:42










  • I don't know dart but I have the feeling you are not linking the two awaits. Are you sure currentRoutineId has a correct value in the second 'await'? Can you check with console or log?
    – Renaud Tarnec
    May 2 '18 at 17:45












  • @RenaudTarnec from what I've seen it gets the correct routineid but it still gives an error in the second foreach
    – merlijn mac gillavry
    May 2 '18 at 17:53










  • What do you exactly want to do? Because it seems all the info is under one node
    – Renaud Tarnec
    May 2 '18 at 18:01














0












0








0







I have this piece of code:



  routineExersiceIDsetter() async{
String routineId;
final response = await reference.child(_userId).once();
response.value.forEach((k,v){
if(v["name"] == "First Routine"){
currentRoutineId = k;
routineId = k;
}
});
final response2 = await reference.child(_userId).child(currentRoutineId).once();
response2.value.forEach((k, v){
if(v["name"] == "Day 1"){
currentSchemeId = k;
}

});
}


and this piece of a firebase database



{
"-LBNflaqFEb4DtZiYxnh" : {
"-LBWa99g4yCstUBkDGa7" : {
"name" : "Day 1"
},
"name" : "First Routine"
}
}


the first forEach line works but the second doesn't. Is there a way to make this work or do I need to change my firebase architecture?










share|improve this question















I have this piece of code:



  routineExersiceIDsetter() async{
String routineId;
final response = await reference.child(_userId).once();
response.value.forEach((k,v){
if(v["name"] == "First Routine"){
currentRoutineId = k;
routineId = k;
}
});
final response2 = await reference.child(_userId).child(currentRoutineId).once();
response2.value.forEach((k, v){
if(v["name"] == "Day 1"){
currentSchemeId = k;
}

});
}


and this piece of a firebase database



{
"-LBNflaqFEb4DtZiYxnh" : {
"-LBWa99g4yCstUBkDGa7" : {
"name" : "Day 1"
},
"name" : "First Routine"
}
}


the first forEach line works but the second doesn't. Is there a way to make this work or do I need to change my firebase architecture?







json firebase dart flutter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 4:54









Cœur

17.4k9103145




17.4k9103145










asked May 2 '18 at 16:51









merlijn mac gillavry

153




153












  • Don't you have to chain the two requests? Queries to Firebase are asynchronous so you should wait the first query resolves to have the value of currentRoutineId and only then you can execute the second query. I don't know how to chain that in dart, so I cannot help you with a full solution.
    – Renaud Tarnec
    May 2 '18 at 17:40












  • @RenaudTarnec I thought I already did that with the await request the perror i get is : type 'String' is not a subtype of type 'int' of 'index'
    – merlijn mac gillavry
    May 2 '18 at 17:42










  • I don't know dart but I have the feeling you are not linking the two awaits. Are you sure currentRoutineId has a correct value in the second 'await'? Can you check with console or log?
    – Renaud Tarnec
    May 2 '18 at 17:45












  • @RenaudTarnec from what I've seen it gets the correct routineid but it still gives an error in the second foreach
    – merlijn mac gillavry
    May 2 '18 at 17:53










  • What do you exactly want to do? Because it seems all the info is under one node
    – Renaud Tarnec
    May 2 '18 at 18:01


















  • Don't you have to chain the two requests? Queries to Firebase are asynchronous so you should wait the first query resolves to have the value of currentRoutineId and only then you can execute the second query. I don't know how to chain that in dart, so I cannot help you with a full solution.
    – Renaud Tarnec
    May 2 '18 at 17:40












  • @RenaudTarnec I thought I already did that with the await request the perror i get is : type 'String' is not a subtype of type 'int' of 'index'
    – merlijn mac gillavry
    May 2 '18 at 17:42










  • I don't know dart but I have the feeling you are not linking the two awaits. Are you sure currentRoutineId has a correct value in the second 'await'? Can you check with console or log?
    – Renaud Tarnec
    May 2 '18 at 17:45












  • @RenaudTarnec from what I've seen it gets the correct routineid but it still gives an error in the second foreach
    – merlijn mac gillavry
    May 2 '18 at 17:53










  • What do you exactly want to do? Because it seems all the info is under one node
    – Renaud Tarnec
    May 2 '18 at 18:01
















Don't you have to chain the two requests? Queries to Firebase are asynchronous so you should wait the first query resolves to have the value of currentRoutineId and only then you can execute the second query. I don't know how to chain that in dart, so I cannot help you with a full solution.
– Renaud Tarnec
May 2 '18 at 17:40






Don't you have to chain the two requests? Queries to Firebase are asynchronous so you should wait the first query resolves to have the value of currentRoutineId and only then you can execute the second query. I don't know how to chain that in dart, so I cannot help you with a full solution.
– Renaud Tarnec
May 2 '18 at 17:40














@RenaudTarnec I thought I already did that with the await request the perror i get is : type 'String' is not a subtype of type 'int' of 'index'
– merlijn mac gillavry
May 2 '18 at 17:42




@RenaudTarnec I thought I already did that with the await request the perror i get is : type 'String' is not a subtype of type 'int' of 'index'
– merlijn mac gillavry
May 2 '18 at 17:42












I don't know dart but I have the feeling you are not linking the two awaits. Are you sure currentRoutineId has a correct value in the second 'await'? Can you check with console or log?
– Renaud Tarnec
May 2 '18 at 17:45






I don't know dart but I have the feeling you are not linking the two awaits. Are you sure currentRoutineId has a correct value in the second 'await'? Can you check with console or log?
– Renaud Tarnec
May 2 '18 at 17:45














@RenaudTarnec from what I've seen it gets the correct routineid but it still gives an error in the second foreach
– merlijn mac gillavry
May 2 '18 at 17:53




@RenaudTarnec from what I've seen it gets the correct routineid but it still gives an error in the second foreach
– merlijn mac gillavry
May 2 '18 at 17:53












What do you exactly want to do? Because it seems all the info is under one node
– Renaud Tarnec
May 2 '18 at 18:01




What do you exactly want to do? Because it seems all the info is under one node
– Renaud Tarnec
May 2 '18 at 18:01












1 Answer
1






active

oldest

votes


















0














I realised is should have wrapped the second ifstatement in another ifstatement:



if(k!="name"){
if(v["name"] == "Day 1"){
currentSchemeId =k;
}
}





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%2f50139785%2fflutter-loop-through-firebase-node-that-consists-of-singlenodes-and-nodes-with-c%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









    0














    I realised is should have wrapped the second ifstatement in another ifstatement:



    if(k!="name"){
    if(v["name"] == "Day 1"){
    currentSchemeId =k;
    }
    }





    share|improve this answer


























      0














      I realised is should have wrapped the second ifstatement in another ifstatement:



      if(k!="name"){
      if(v["name"] == "Day 1"){
      currentSchemeId =k;
      }
      }





      share|improve this answer
























        0












        0








        0






        I realised is should have wrapped the second ifstatement in another ifstatement:



        if(k!="name"){
        if(v["name"] == "Day 1"){
        currentSchemeId =k;
        }
        }





        share|improve this answer












        I realised is should have wrapped the second ifstatement in another ifstatement:



        if(k!="name"){
        if(v["name"] == "Day 1"){
        currentSchemeId =k;
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 2 '18 at 21:45









        merlijn mac gillavry

        153




        153






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f50139785%2fflutter-loop-through-firebase-node-that-consists-of-singlenodes-and-nodes-with-c%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

            Full-time equivalent

            Bicuculline

            さくらももこ