我正在尝试将此列表作为流返回,但出现以下错误:
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>?>'.
下面的清单是导致这些错误的代码:
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 = [];
}
}
我还想知道如何在 中声明它MultiProviders
,我是否使用Provider.of
我是 Streams 的新手。这个错误的原因是什么?