I cannot access my firebase/firecloud data from my flutter project. I get: Could not reach Cloud Firestore backend. Connection failed 1 times

424
  1. First include firebase_core in your dependencies firebase_core: ^1.3.0.
  2. The screenshot you sent is firebase Realtime database (rtdb). But what you are trying to reach is cloud firestore. Did you setup cloud firestore? Confirm by going to firebase console and clicking cloud firestore by the left. Check if it is setup and if you have any data in the 'controls' collection.
  3. Go to the link given in 'errors screenshot' that you posted and enable cloud firestore api.

NB: Cloud firestore and Realtime database are 2 different firebase databases. You can visit this link to learn about their differences and decide which one to use.

Share:
424
kojo justine
Author by

kojo justine

Updated on December 31, 2022

Comments

  • kojo justine
    kojo justine over 1 year

    I have been stuck with this for days now, I have difficulty accessing my firebase database from my flutter project. I have followed all the instructions to adding firebase to an android app on flutter and tried many suggested solutions on the web but I'm still stuck. I hope someone will be patient or kind enough to help me out. I have put all the necessary snippets below.

    My dependencies

        dependencies:
          flutter:
            sdk: flutter
          google_maps_flutter: ^2.0.6
          proj4dart: ^2.0.0
          location: ^4.2.0
          cloud_firestore: ^2.5.1
          firebase_core: ^1.6.0
    

    my imports

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

    My firestore structure enter image description here

    my function to retrieve the data from firestore

      Future getControls() async{
          await Firebase.initializeApp();
    
        FirebaseFirestore firestoreInstance = FirebaseFirestore.instance;
    
        QuerySnapshot data =  await firestoreInstance.collection('Controls').get();
    
      }
    

    Error received enter image description here

    My google service JSON file

    enter image description here

    My Buld.gradle file enter image description here

    **

    I may not be doing it right, or there is something I'm missing. Can someone please help me out .... mmmhh. Thanks in Advance

    **

  • kojo justine
    kojo justine over 2 years
    O, thanks for the corrections. I have added the firebase_core dependency to my project. I have now setup a cloud firetore database and also, I have enabled the API. however, I am still receiving similar errors: Listen for Query(target=Query(controls order by name);limitType=LIMIT_TO_FIRST) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null} Any ideas where to go next?
  • kojo justine
    kojo justine over 2 years
    ok. I changed the rules at the firestore into: allow read, write;
  • Peter Obiechina
    Peter Obiechina over 2 years
    Awesome. Glad I could help.