1

there is an array in every document which contains a map (list) of songs and i want to Stream (read) them here in this page but i get this error

type 'List<dynamic>' is not a subtype of type 'String'
body: StreamBuilder(
        stream: Firestore.instance.collection('singers').snapshots(),
        builder: (
          context,
          snapshot,
        ) {
          *if statement*
          return ListView.builder(
                itemCount: snapshot.data.documents.length,
                itemBuilder: (context, index) => SingleChildScrollView(
                      child: Padding(
                        padding: const EdgeInsets.only(
                            left: 10, right: 10, top: 10, bottom: 0),
                        child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                Text(
                                  snapshot.data.documents[index]['songs list'],
                                  style: TextStyle(
                                      fontSize: 20, color: Colors.red[500]),
                                )
                              ]),
                        ),
                      ),
                    )),
          );
        },
      ),
    );
  }
}

Database db

2 Answers 2

1

Looking at your database and the error message it looks like the array object songs list is the List<dynamic> that is the issue. Instead if you want the Text widget to output the list of songs try

snapshot.data.documents[index]['songs list'].map((e) => e.values.join(,)).join(',')

which will convert the List<dynamic> into a string of values separated by a comma

Sign up to request clarification or add additional context in comments.

4 Comments

It ia a list of Map. The snapshot.data.documents[index]['songs list'] returns a List of Map objects.
Ah okay, thanks I didn't realise, I've updated my answer to map the list of Maps into strings of their values, then you can join all those into a list of song. If that's your intention.
it works man but it reads all the array in one line and from all the documents. i want it from a single document and every item from an array in a new line since its a ListView.Builder inside a StreamBuilder
Hey, sorry I missed your reply and sorry about the misunderstanding. From what I can see from your code the list is looping through the documents array itself, so one list item = one document. Therefore the songs are output for every document. If you want the song list for one document could you do a high level list of documents (the list you have at the moment) where the list item is the doc title, the user could then tap into it (or expand or something else) to see a list of songs. This list would be built by making a ListView for snapshot.data.documents[index]['songs list']
0

Try this :

snapshot.data.documents['songs list'][index]['jigar]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.