I am trying to get a document reference from a string. I have the following:
www.site.com/page?foo=bar
When I go to the page, I want my OnLoad action to get the data from 'collectionName/bar' so I need to convert this 'collectionName/ + bar' into a document reference.
I am currently doing the following:
DocumentReference? convertStringToDocumentReference(String docID) {
/// MODIFY CODE ONLY BELOW THIS LINE
final theStr = 'collecionName/' + docID;
final theRef = theStr as DocumentReference;
return theRef;
/// MODIFY CODE ONLY ABOVE THIS LINE
}
But I get the following error.
TypeError: "collectionName/bar": type 'JSString' is not a subtype of type 'DocumentReference'
I've tried this as well
DocumentReference? convertStringToDocumentReference(String docID) {
/// MODIFY CODE ONLY BELOW THIS LINE
return FirebaseFirestore.instance.collection('collectionName').doc(docID);
/// MODIFY CODE ONLY ABOVE THIS LINE
}
But then I get the error:
Error: Undefined name 'FirebaseFirestore'.
return FirebaseFirestore.instance.collection('collectionName').doc(docID);