skip to Main Content

I try to update list of userUid at the same time but it says this The argument type ‘List’ can’t be assigned to the parameter type ‘String?’

              StreamBuilder(
                          stream: FirebaseFirestore.instance
                              .collection("groups")
                              .doc(groupId)
                              .snapshots(),
                          builder: (context,
                              AsyncSnapshot<DocumentSnapshot> snapshot) {
                            var userDocumentUid = snapshot1.data?["members"];
                            if (!snapshot.hasData) {
                              return Container();
                            }
                            return ... 
    //Elevated Button
    onPressed: () async => {
             await DataBase().deleteGroup(userDocumentUid)
    }
    //My DataBase
        Future<String> deleteGroup(String List<dynamic> userDocumentUid) async {
            String retVal = "error";
            try {
             await firestore
                  .collection("users")
                  .doc(userDocumentUid)
                  .update({'groupId': ""});
        
              retVal = "success";
            } catch (e) {
              // ignore: avoid_print
              print(e);
            }
            return retVal;
          }

Is there anyway to get the doc as list not as only a string?

2

Answers


  1. It seems like snapshot1.data?["members"] is returning a string thus initializing the userDocumentUid a string type.
    Try
    userDocumentUid[0] = snapshot1.data?["members"];
    this will make a list

    Login or Signup to reply.
  2. The error comes up when you are trying to return an argument type which is a list value with a mismatched parameter subtype.
    To get the list data try below code after execution of the below code all the ids will be stored in the list ids

    List<String> ids=[]; 
    QuerySnapshot snapshot=await FirebaseFirestore.instance.collection('following').document(widget.currentUser.id).collection("userFollowing").getDocuments();
    snapshot.documents.forEach((doc) { ids.add(doc.documentID); });
    

    You may check the documentation available for more details on List collection and Argument Type error

    UPDATE

    final QuerySnapshot result = await Firestore.instance.collection('myCollection').getDocuments();
    final List<DocumentSnapshot> documents = result.documents;
    

    and after that you can loop through it with

    documents.forEach((data) => print(data));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search