I'm trying to return this List as a Stream, but I'm getting the below errors:
1. The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type.
2. A value of type 'Future<QuerySnapshot<Map<String, dynamic>>>' can't be assigned to a variable of type 'QuerySnapshot<Object?>'.
3. A value of type 'List<dynamic>?' can't be returned from the method 'userBookmarkedCourses' because it has a return type of 'Stream<List<dynamic>?>'.
Listing below is the code that is causing these errors:
Stream<List<dynamic>?> userBookmarkedCourses() {
print("User Id within User Provider: $userId");
QuerySnapshot userSnapshot;
try {
if (userId != null) {
userSnapshot = FirebaseFirestore.instance.collection('users').where('userID', isEqualTo: userId).get();
if (userSnapshot.docs.isNotEmpty) {
return coursesBookmarkedList = userSnapshot.docs[0].get('coursesBookmarked');
}
return coursesBookmarkedList = [];
}
} catch (error) {
coursesBookmarkedList = [];
}
}
I would also like to know how to declare this within the MultiProviders
and do I consume it using the Provider.of
I'm new to Streams. What is the cause of this error?