The getter 'instance' isn't defined for the type 'Firestore'

前端 未结 2 1541
陌清茗
陌清茗 2020-11-29 13:12

Hi guys when i\'m trying to declare a instance of Firestore he give this error ! all that\'s happening after i upgrade my Flutter to last version

相关标签:
2条回答
  • 2020-11-29 13:28

    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

    0 讨论(0)
  • 2020-11-29 13:46

    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

    0 讨论(0)
提交回复
热议问题