type 'String' is not a subtype of type 'int' of 'index' StreamBuilder<QuerySnapshot>

Viewed 69

Hi all I'm new in flutter, I'm sorry if i even asking stupid question here. I am getting error when running in flutter

_StreamBuilderBaseState<QuerySnapshot<Map<String, dynamic>>, AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>>>#ad7d9): type 'String' is not a subtype of type 'int' of 'index'

The relevant error-causing widget was: StreamBuilder<QuerySnapshot<Map<String, dynamic>>> StreamBuilder:file:///C:/Users/rohay/StudioProjects/roro_medicine_reminder/lib/screens/main/home/JagaMe/contact_relatives_screen.dart:73:13

Here is my code of contact_relatives_screen.dart that has error

body: ListView(
          children: <Widget>[
            StreamBuilder(
                stream: FirebaseFirestore.instance
                    .collection('profile')
                    .doc(userId)
                    .collection('relatives')
                    .snapshots(),
                builder: (context, snapshot) {
                  if (snapshot.hasData) {
                    List<Widget> relativesWidget = [];
                    recipients = [];
                    var data = snapshot.data.docs[''];
                    if (data != null) {
                      userProfile.getAllRelatives(data);
                      if (data.length > 0) relativesFound = true;
                      for (var relative in userProfile.relatives) {
                        recipients.add(relative.phoneNumber);
                        relativesWidget.add(RelativeDetail(
                          name: relative.name,
                          email: relative.email,
                          number: relative.phoneNumber,
                          documentID: relative.documentID,
                          userId: userId,
                        ));
                      

How to fix the error ya? Many thanks

Also atttach is the screenshot of the error.

enter image description here

0 Answers
Related