Mt Khalifa
Mt Khalifa

Reputation: 498

i want to read data from map inside array in flutter

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

Upvotes: 1

Views: 2692

Answers (2)

Giles Correia Morton
Giles Correia Morton

Reputation: 872

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

Upvotes: 1

Adarsh Balu
Adarsh Balu

Reputation: 352

Try this :

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

Upvotes: 0

Related Questions