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
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
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
You may check the documentation available for more details on List collection and Argument Type error
UPDATE
and after that you can loop through it with