Reputation: 65
import 'dart:html';
import 'package:cloud_firestore/cloud_firestore.dart';
class FirestoreService {
FirebaseFirestore _db = FirebaseFirestore.instance;
//Get Entries
Stream<List<Entry>> getEntries() {
return _db
.collection('entries')
.snapshots()
.map((snapshot) => snapshot.docs
.map((doc) => Entry.fromJson(doc.data()))
.toList());
}
//Create
//Update
//Delete
}
Hi, this is my code Im getting this error which says the return type List(dynamic) isn't a List(Entry), as required by the closures's context. How to rectify this? Thanks
Upvotes: 1
Views: 1288
Reputation: 2705
Give map
some help by providing a type:
.map<Entry>((doc) => Entry.fromJson(doc.data()))
The whole method would be:
//Get Entries
Stream<List<Entry>> getEntries() {
return _db
.collection('entries')
.snapshots()
.map((snapshot) => snapshot.docs
.map<Entry>((doc) => Entry.fromJson(doc.data()))
.toList());
}
Your method returns a List<Entry>
but the return expression returns a List<dynamic>
unless you explicitly cast the result to Entry
.
Adding the type should solve the problem.
Upvotes: 3