Flutter Firestore FutureBuilder filter with if statement












0















I'm trying to filter a list of a FutureBuilder as follows:



return new FutureBuilder(
future: Firestore.instance
.collection('user')
.getDocuments(),
builder: (BuildContext context, AsyncSnapshot snapshot2) {
if (snapshot2.hasData) {
if (snapshot2.data != null) {
return new Column(
children: <Widget>[
new Expanded(
child: new ListView(
children: snapshot2.data.documents
.map<Widget>((DocumentSnapshot document) {
if(document['first_name'] == 'James') {
return new FindFollowerWidget(
name: document['first_name'] + " " + document['last_name'],
username: document['username'],
);
}
}).toList(),
),
),
],
);
}
}else {
return new CircularProgressIndicator();
}
});


This FutureBuilder works when I remove the if statement; however, when I include the following if statement it Flutter throws an error:



new ListView(
children: snapshot2.data.documents.map<Widget>((DocumentSnapshot document) {
if(document['first_name'] == 'James') {
return new FindFollowerWidget(
name: document['first_name'] + " " + document['last_name'],
username: document['username'],
);
}
).toList(),
),


My question: how can I only return the FindFollowerWidget when a document snapshot field has a specific value (in this case the first name being "James"?



Thanks!










share|improve this question

























  • which if statement , you have used three if statement .?

    – anmol.majhail
    Nov 23 '18 at 19:12











  • remove snapshot2.data != null . Isn't necessary .

    – Rubens Melo
    Nov 23 '18 at 19:29











  • @anmol.majhail Edited to add clarity. The question is about the if statement within the ListView. Would love any thoughts you have about how to get this to work!

    – PJQuakJag
    Nov 23 '18 at 19:44











  • Use ListView.builder you can run the if Statement in the itemBuilder.

    – anmol.majhail
    Nov 23 '18 at 19:48
















0















I'm trying to filter a list of a FutureBuilder as follows:



return new FutureBuilder(
future: Firestore.instance
.collection('user')
.getDocuments(),
builder: (BuildContext context, AsyncSnapshot snapshot2) {
if (snapshot2.hasData) {
if (snapshot2.data != null) {
return new Column(
children: <Widget>[
new Expanded(
child: new ListView(
children: snapshot2.data.documents
.map<Widget>((DocumentSnapshot document) {
if(document['first_name'] == 'James') {
return new FindFollowerWidget(
name: document['first_name'] + " " + document['last_name'],
username: document['username'],
);
}
}).toList(),
),
),
],
);
}
}else {
return new CircularProgressIndicator();
}
});


This FutureBuilder works when I remove the if statement; however, when I include the following if statement it Flutter throws an error:



new ListView(
children: snapshot2.data.documents.map<Widget>((DocumentSnapshot document) {
if(document['first_name'] == 'James') {
return new FindFollowerWidget(
name: document['first_name'] + " " + document['last_name'],
username: document['username'],
);
}
).toList(),
),


My question: how can I only return the FindFollowerWidget when a document snapshot field has a specific value (in this case the first name being "James"?



Thanks!










share|improve this question

























  • which if statement , you have used three if statement .?

    – anmol.majhail
    Nov 23 '18 at 19:12











  • remove snapshot2.data != null . Isn't necessary .

    – Rubens Melo
    Nov 23 '18 at 19:29











  • @anmol.majhail Edited to add clarity. The question is about the if statement within the ListView. Would love any thoughts you have about how to get this to work!

    – PJQuakJag
    Nov 23 '18 at 19:44











  • Use ListView.builder you can run the if Statement in the itemBuilder.

    – anmol.majhail
    Nov 23 '18 at 19:48














0












0








0








I'm trying to filter a list of a FutureBuilder as follows:



return new FutureBuilder(
future: Firestore.instance
.collection('user')
.getDocuments(),
builder: (BuildContext context, AsyncSnapshot snapshot2) {
if (snapshot2.hasData) {
if (snapshot2.data != null) {
return new Column(
children: <Widget>[
new Expanded(
child: new ListView(
children: snapshot2.data.documents
.map<Widget>((DocumentSnapshot document) {
if(document['first_name'] == 'James') {
return new FindFollowerWidget(
name: document['first_name'] + " " + document['last_name'],
username: document['username'],
);
}
}).toList(),
),
),
],
);
}
}else {
return new CircularProgressIndicator();
}
});


This FutureBuilder works when I remove the if statement; however, when I include the following if statement it Flutter throws an error:



new ListView(
children: snapshot2.data.documents.map<Widget>((DocumentSnapshot document) {
if(document['first_name'] == 'James') {
return new FindFollowerWidget(
name: document['first_name'] + " " + document['last_name'],
username: document['username'],
);
}
).toList(),
),


My question: how can I only return the FindFollowerWidget when a document snapshot field has a specific value (in this case the first name being "James"?



Thanks!










share|improve this question
















I'm trying to filter a list of a FutureBuilder as follows:



return new FutureBuilder(
future: Firestore.instance
.collection('user')
.getDocuments(),
builder: (BuildContext context, AsyncSnapshot snapshot2) {
if (snapshot2.hasData) {
if (snapshot2.data != null) {
return new Column(
children: <Widget>[
new Expanded(
child: new ListView(
children: snapshot2.data.documents
.map<Widget>((DocumentSnapshot document) {
if(document['first_name'] == 'James') {
return new FindFollowerWidget(
name: document['first_name'] + " " + document['last_name'],
username: document['username'],
);
}
}).toList(),
),
),
],
);
}
}else {
return new CircularProgressIndicator();
}
});


This FutureBuilder works when I remove the if statement; however, when I include the following if statement it Flutter throws an error:



new ListView(
children: snapshot2.data.documents.map<Widget>((DocumentSnapshot document) {
if(document['first_name'] == 'James') {
return new FindFollowerWidget(
name: document['first_name'] + " " + document['last_name'],
username: document['username'],
);
}
).toList(),
),


My question: how can I only return the FindFollowerWidget when a document snapshot field has a specific value (in this case the first name being "James"?



Thanks!







flutter google-cloud-firestore






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 19:43







PJQuakJag

















asked Nov 23 '18 at 18:55









PJQuakJagPJQuakJag

629




629













  • which if statement , you have used three if statement .?

    – anmol.majhail
    Nov 23 '18 at 19:12











  • remove snapshot2.data != null . Isn't necessary .

    – Rubens Melo
    Nov 23 '18 at 19:29











  • @anmol.majhail Edited to add clarity. The question is about the if statement within the ListView. Would love any thoughts you have about how to get this to work!

    – PJQuakJag
    Nov 23 '18 at 19:44











  • Use ListView.builder you can run the if Statement in the itemBuilder.

    – anmol.majhail
    Nov 23 '18 at 19:48



















  • which if statement , you have used three if statement .?

    – anmol.majhail
    Nov 23 '18 at 19:12











  • remove snapshot2.data != null . Isn't necessary .

    – Rubens Melo
    Nov 23 '18 at 19:29











  • @anmol.majhail Edited to add clarity. The question is about the if statement within the ListView. Would love any thoughts you have about how to get this to work!

    – PJQuakJag
    Nov 23 '18 at 19:44











  • Use ListView.builder you can run the if Statement in the itemBuilder.

    – anmol.majhail
    Nov 23 '18 at 19:48

















which if statement , you have used three if statement .?

– anmol.majhail
Nov 23 '18 at 19:12





which if statement , you have used three if statement .?

– anmol.majhail
Nov 23 '18 at 19:12













remove snapshot2.data != null . Isn't necessary .

– Rubens Melo
Nov 23 '18 at 19:29





remove snapshot2.data != null . Isn't necessary .

– Rubens Melo
Nov 23 '18 at 19:29













@anmol.majhail Edited to add clarity. The question is about the if statement within the ListView. Would love any thoughts you have about how to get this to work!

– PJQuakJag
Nov 23 '18 at 19:44





@anmol.majhail Edited to add clarity. The question is about the if statement within the ListView. Would love any thoughts you have about how to get this to work!

– PJQuakJag
Nov 23 '18 at 19:44













Use ListView.builder you can run the if Statement in the itemBuilder.

– anmol.majhail
Nov 23 '18 at 19:48





Use ListView.builder you can run the if Statement in the itemBuilder.

– anmol.majhail
Nov 23 '18 at 19:48












1 Answer
1






active

oldest

votes


















2














I'm not so sure about what you are asking. Probably List.where() method?



snapshot2.data.document
.where((document)=>document["first_name"]=="James")
.map((document)=>FindFollowerWidget(...))
.toList();





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%2f53451737%2fflutter-firestore-futurebuilder-filter-with-if-statement%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









    2














    I'm not so sure about what you are asking. Probably List.where() method?



    snapshot2.data.document
    .where((document)=>document["first_name"]=="James")
    .map((document)=>FindFollowerWidget(...))
    .toList();





    share|improve this answer




























      2














      I'm not so sure about what you are asking. Probably List.where() method?



      snapshot2.data.document
      .where((document)=>document["first_name"]=="James")
      .map((document)=>FindFollowerWidget(...))
      .toList();





      share|improve this answer


























        2












        2








        2







        I'm not so sure about what you are asking. Probably List.where() method?



        snapshot2.data.document
        .where((document)=>document["first_name"]=="James")
        .map((document)=>FindFollowerWidget(...))
        .toList();





        share|improve this answer













        I'm not so sure about what you are asking. Probably List.where() method?



        snapshot2.data.document
        .where((document)=>document["first_name"]=="James")
        .map((document)=>FindFollowerWidget(...))
        .toList();






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 19:48









        First_StrikeFirst_Strike

        1229




        1229
































            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%2f53451737%2fflutter-firestore-futurebuilder-filter-with-if-statement%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

            To store a contact into the json file from server.js file using a class in NodeJS

            Marschland

            Wiesbaden