The getter 'instance' isn't defined for the type 'Firestore'
Solution 1:
Starting from cloud_firestore
version 0.14.0:
In the newest version of cloud_firestore
, the class Firestore
was deprecated now you have to use FirebaseFirestore
, so just do:
Import the package:
import 'package:cloud_firestore/cloud_firestore.dart'
To create an instance:
final databaseReference = FirebaseFirestore.instance;
Other Links Regarding The Changes on Firebase:
No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() in Flutter and Firebase
Undefined class 'FirebaseUser'
cloud_firestore 0.14.0 how to use the data method
Solution 2:
Cloud_firestore version 0.14.0 has the following changes: import the package:
import 'package:firebase_auth/firebase_auth.dart';
FirebaseUser is not longer available. To declare a Firebase User, use the Following; //User,
To declare a Firebase instance, use:
final firebaseInstance= FirebaseFirestore.instance;
instead of the calling of .document(uid), use:
.doc(uid)
for example:
await db
.collection(Str.USERS_MESSAGE_LIST)
.document(uid)
.collection(Str.MESSAGE_COLLECTION)
.document("$itemId$sellerId")
.setData({...
will become:
await db
.collection(Str.USERS_MESSAGE_LIST)
.doc(uid)//note this
.collection(Str.MESSAGE_COLLECTION)
.document("$itemId$sellerId")
.set({//note this
Similary for other queries, use of .data() as opposed to .data([]} e.g.
.startAfter([lastDocument.data[Str.ITEM_NAME]]).limit(perPage);
will re-written as:
.startAfter([lastDocument.data()[Str.ITEM_NAME]]).limit(perPage);//note the () after data
For a user: use:
User user = FirebaseAuth.instance.currentUser;
And many other changes - refer to official Firestore/Firebase documentation