簡體   English   中英

撲動未定義的類'FirebaseFirestore'

[英]flutter undefined class 'FirebaseFirestore'

我正在嘗試將數據從 firebase firestore 獲取到我正在構建的應用程序,這似乎很好,但我在控制台上收到了這條消息:

[Firestore]: The behavior for java.util.Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK.
W/Firestore( 8224): To hide this warning and ensure your app does not break, you need to add the following code to your app before calling any other Cloud Firestore methods:
W/Firestore( 8224): 
W/Firestore( 8224): FirebaseFirestore firestore = FirebaseFirestore.getInstance();
W/Firestore( 8224): FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
W/Firestore( 8224):     .setTimestampsInSnapshotsEnabled(true)
W/Firestore( 8224):     .build();
W/Firestore( 8224): firestore.setFirestoreSettings(settings);

我正在使用包

 import 'package:flutter/material.dart';
 import 'auth.dart';
 import 'state_rut.dart';
 import 'package:cloud_firestore/cloud_firestore.dart';

獲取信息的代碼如下:

final collection = Firestore.instance.collection('regions');
collection.orderBy('region_id').getDocuments()
    .then((data){
      print(data);
    })
    .catchError((e){
       print(e);
    });

我一開始想使用頁面https://firebase.google.com/docs/firestore/quickstart中的那個,這顯然是我需要的,但是當我在應用程序上鍵入 FirebaseFirestore firestore = FirebaseFirestore.getInstance() ; 我收到消息錯誤 undefined class 'FirebaseFirestore'。

我錯過了什么? 我在 pubspec.yaml 上的一切都很好,所有的包都在工作

順便說一句,我正在嘗試獲取數據,以便可以基於此構建一個下拉按鈕

如果您不使用時間戳,則可以放心地忽略它。 可能是這種情況,因為您才剛剛開始使用它。

這是警告,而不是錯誤。 提醒您,如果使用Firestore時間戳,則需要為timestampsInSnapshots使用指定的設置,如果不使用該設置,則會中斷應用程序。

導入這個:

import 'package:cloud_firestore/cloud_firestore.dart';

並改用它:

FirebaseFirestore.instance

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM