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

前端 未结 2 1553
陌清茗
陌清茗 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

提交回复
热议问题