I got a problem. When I want to sort documents with Firestore, I need to return the Query type. So, when I return this type in the addNote
method, I get an error in .doc
Tell me how to write a method correctly to get rid of this error?
firestore_repository
class Database {
Query<Map<String, dynamic>> getMainCollection() {
FirebaseFirestore firestore = FirebaseFirestore.instance;
return firestore.collection('notes').orderBy('date');
}
Future<void> addNote(
String name,
String title,
String? date,
) {
Query<Map<String, dynamic>> mainCollection = getMainCollection();
return mainCollection
.doc()
.set({'name': name, 'title': title, 'date': date})
.then((value) => print('Note Added'))
.catchError((error) => print('Failed to add note: $error'));
}