I'm having some trouble getting printing out a string in a firestore document, and it's only returning null. Anything that might be going wrong?
String getDoc(String group, String channel, String message)
{
var data;
final docRef = db.collection('Groups').doc('$group').collection('Channel').doc('$channel').collection('Messages').doc('$message');
docRef.get().then(
(DocumentSnapshot doc) {
data = doc.data() as Map<String, dynamic>;
},
onError: (e) => print("Error getting document: $e"),
);
print(data);
var returnMessage = data?['messageBody'];
print(returnMessage);
return returnMessage;
}
this is the current message. ======== Exception caught by gesture =============================================================== The following TypeErrorImpl was thrown while handling a gesture: Expected a value of type 'String', but got one of type 'Null'