Reputation: 63
FirebaseFirestore.instance
.collection('women')
.snapshots()
.map((snapshot) => snapshot.docs
.map((document) => CategoryAvatar.fromJson({...document.data()}))
.toList())
.listen((avatar) {
avatarsInfo.addAll(avatar);
when I started to debug, this exception occurred in the IDE at the third line of the code shown above :
Exception has occurred. NoSuchMethodError (NoSuchMethodError: The method 'add' was called on null. Receiver: null Tried calling: add(Instance of 'MethodChannelQuerySnapshot'))
also when I was debugging, the debugger always does pass the fifth and sixth lines for some weird reason, I mean those lines can't be executed by the program.
when I run the code, the text below is displayed on the debugging console
D/HwCustConnectivityManagerImpl( 8132): isBlockNetworkRequestByNonAis, INVALID_SUBSCRIPTION_ID D/ConnectivityManager( 8132): requestNetwork and the calling app is: com.sincerity.sandra W/DynamiteModule( 8132): Local module descriptor class for providerinstaller not found. I/DynamiteModule( 8132): Considering local module providerinstaller:0 and remote module providerinstaller:0 W/ProviderInstaller( 8132): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0. D/HwCustConnectivityManagerImpl( 8132): isBlockNetworkRequestByNonAis, INVALID_SUBSCRIPTION_ID
Upvotes: 1
Views: 2227
Reputation: 63
the problem has been solved by adding the await keyword at the beginning of the query
await _firebaseFirestore.collection('women').get().then(
(QuerySnapshot querySnapshot) {
querySnapshot.docs.forEach(
(doc) {
avatarsInfo.add(
CategoryAvatar.fromJson(
{
...doc.data(),
},
),
);
},
);
},
);
Upvotes: 1
Reputation: 3460
Try this is it works but it only retrieves the data one cycle.
FirebaseFirestore.instance.collection('women').snapshots().map((snapshot) {
snapshot.documents.forEach((snapshot) {
print(snapshot.data);
CategoryAvatar avatar = CategoryAvatar.fromJson(snapshot.data());
avatarsInfo.addAll(avatar);
});
}).toList();
If your streaming the data try this
Stream<List<CategoryAvatar>> avatarList() {
return FirebaseFirestore.instance.collection('women').
.snapshots()
.map((value) => value.documents
.map((result) => CategoryAvatar.fromJson(result.data()))
.toList());
}
i hope i helped you
Upvotes: 0