Ryan
Ryan

Reputation: 25

Return String from Map in collection firebase & Flutter

I am trying to return the strings in this map in a collection. I would like to return all strings that are marked as true but I am not sure how to do that. Attached is a screenshot of my firebase setup. Any help would be much appreciated. enter image description here

Upvotes: 0

Views: 116

Answers (1)

jbryanh
jbryanh

Reputation: 2013

Assuming you know how to get the snapshots, and each document has only one question, which is what you have pictured:

Map<String, Map<String, bool>> questions = snapshot.data();

questions.forEach((question, options) {
  options.forEach((option, value) {
    if (value) {return option;}
  });
});

question is fourthQuestion.

option is each possible answer? 1-2, 13 or more etc.

and value is t/f

Upvotes: 1

Related Questions