0

Here is my code, slightly adapted from the example in flutter documentation:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';

@override
Widget build(BuildContext context) {

CollectionReference items = FirebaseFirestore.instance.collection('item');

return FutureBuilder<DocumentSnapshot>(
  future: items.doc(itemId).get(),
  builder:
      (BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) {

    if (snapshot.hasError) {
      return Text("Something went wrong");
    }

    if (snapshot.connectionState == ConnectionState.done) {
      Map<String, dynamic> data = snapshot.data.data();
      return data['out_of_stock_location_ids'];// ${data['last_name']}");
    }

    return Text("loading");
  },
);

}

The code "FirebaseFirestore" is giving an error as it's not recognized as part of library that I'm imported. The import 'package:firebase_core/firebase_core.dart'; is grayed out, possibly inappropriately so. I can't find where on the internet I can find why this is occurring or what to do about it.

0

4 Answers 4

1

If you are using cloud_firestore: 0.14.0 version and above you need to use FirebaseFirestore & doc() then if cloud_firestore: 0.13.7+1 and below you need to use Firestore & document().

The documentation you mentioned is updated and I believe you are using now the lower version of cloud_firestore. If you want to use the higher or latest version of cloud_firestore you must change the version of your firestore in pubspec.yaml then visit the changelog of firestore in pub.dev to see the every changes and update of firestore.

Sign up to request clarification or add additional context in comments.

1 Comment

Let me know if you tried the new version and the issue persist.
0

I'm not sure but you probably didn't initialize firebase in your main method you had to use firebase core for initialization

import core to main.dart

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

Comments

0

It appears that the documentation is outdated. I had to change FirebaseFirestore to Firestore and doc to document. I'm not sure how people are supposed to know to do that.

Comments

0

Go to this website=>

https://pub.dev/packages/cloud_firestore/install

Copy the terminal code => flutter pub add cloud_firestore

after paste over your terminal and hit enter.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.