【问题标题】:Undefined name 'Firestore' Flutter未定义的名称“Firestore”颤振
【发布时间】:2021-02-06 07:46:58
【问题描述】:
dependencies:
  flutter:
    sdk: flutter
    


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  cloud_firestore:

我配置正确,请帮忙

【问题讨论】:

  • 将 cupertino_icons: ^1.0.2 和 cloud_firestore: 放在 pubspec.yaml 文件的不同行中。
  • 是的,它在不同的行中
  • 您能解释一下您遇到的问题吗?您是否收到了特定的错误消息?
  • prntscr.com/yhu78y 我想使用单个查询搜索firestore,它显示方法'getDocuments' 没有为'Query' 类型定义。有什么帮助吗?

标签: firebase flutter google-cloud-firestore


【解决方案1】:

没有名为Firestore 的类。请改用FirebaseFirestore.instance。

示例:

var snapshot = FirebaseFirestore.instance
          .collection('chat')
          .orderBy('createdAt', descending: true)
          .snapshots();

【讨论】:

    【解决方案2】:

    使用这个 pubspec.yaml

    cloud_firestore: ^0.13.5

    【讨论】:

      【解决方案3】:

      将名称从“Firestore”更改为“FirebaseFirestore”。

      【讨论】:

        【解决方案4】:

        示例

        安装依赖:-

        dependencies:
          flutter:
            sdk: flutter
        
        
          # The following adds the Cupertino Icons font to your application.
          # Use with the CupertinoIcons class for iOS style icons.
          cupertino_icons: ^1.0.0
          firebase_auth:
          cloud_firestore: ^0.14.3
          firebase_core: ^0.5.2
        

        导入包:-

        import 'package:cloud_firestore/cloud_firestore.dart';
        

        访问 Firestore:-

        Future getMembers() async {
            var firestore = FirebaseFirestore.instance;
            QuerySnapshot querySnapshot = await firestore.collection("Members").get();
            final documents = querySnapshot.docs;
            return documents
        }
        

        【讨论】:

          猜你喜欢
          • 2021-05-01
          • 2021-01-17
          • 2021-03-28
          • 2022-01-25
          • 2021-11-06
          • 1970-01-01
          • 2021-08-12
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多