简体   繁体   中英

flutter undefined class 'FirebaseFirestore'

I am trying to get data from firebase firestore to the app I am building, it seems to be quite fine but I recieve this message on the console:

[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);

I am using the packages

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

and the code ttying to get the info goes:

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

I wanted to use at first the one in the page https://firebase.google.com/docs/firestore/quickstart which apparently was the one I needed but when I type on the app the line FirebaseFirestore firestore = FirebaseFirestore.getInstance(); I get the message error undefined class 'FirebaseFirestore'.

What is it I am missing? I have everything good on the pubspec.yaml, and all the packages are working

By the way I am trying to get the data so I can build based on this a dropdownbutton

If you're not using timestamps, you can safely ignore it. This is probably the case since you're just starting to use it.

It's a warning, rather than an error. It's a reminder that if you use Firestore timestamps, you need to use the specified setting for the timestampsInSnapshots, which will break apps if not used.

Import this:

import 'package:cloud_firestore/cloud_firestore.dart';

And use this instead:

FirebaseFirestore.instance

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM