Tomee
Tomee

Reputation: 139

"The method 'getDocuments' isn't defined for the type 'DatabaseReference'." Flutter - Firebase

i am have some difficulties with saving my list of items inside a function as i do get an error "The method 'getDocuments' isn't defined for the type 'DatabaseReference'." I don't have any clue how to fix it maybe someone could be so kind and explain what I'm doing wrong.

Here is function code snippet

getItemStreamSnapshots() async {
var data = await FirebaseDatabase.instance
    .reference()
    .child("Book")
    .getDocuments();

setState(() {
  _allResults = data.documents;
});
searchResultsList();
return "complete";
}

Here's how my DB looks like

Upvotes: 0

Views: 2451

Answers (2)

Kim
Kim

Reputation: 31

Since 0.14.0 Query

DEPRECATED: Calling getDocuments() is deprecated in favor of get().

BREAKING: getDocuments/get has been updated to accept an instance of GetOptions (see below).

NEW: Query methods can now be chained.

NEW: It is now possible to call same-point cursor based queries without throwing (e.g. calling endAt() and then endBefore() will replace the "end" cursor query with the endBefore).

NEW: Added support for the limitToLast query modifier.

link: https://pub.dev/packages/cloud_firestore/changelog#0140

Upvotes: 3

Renaud Tarnec
Renaud Tarnec

Reputation: 83113

A DatabaseReference does not have a getDocuments() method. You should either use the once() method or the onValue property, if you want to read the data corresponding to the DatabaseReference.

You will find more details on how to use the Realtime Database with Flutter in the two following articles: "How to use Firebase realtime database with Flutter" and "How to use Firebase Queries In Flutter".

Upvotes: 1

Related Questions