2

I am trying to complete a very simple exercise by connecting my basic Flutter app to Cloud Firestore (in Firebase).

I have followed the instructions with regards to setup. However, I am getting the following error.

E/MethodChannel#plugins.flutter.io/cloud_firestore(13217): Failed to handle method call
E/MethodChannel#plugins.flutter.io/cloud_firestore(13217): java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.

My flutter code:

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Playground',
        home: Scaffold(
            appBar: AppBar(
              title: Text('Playground App'),
            ),
            body: Column(children: <Widget>[
              Text('Sup World?'),
            StreamBuilder(
              stream: Firestore.instance.collection('test').snapshots(),
              builder: (context, snapshot) {
                if (!snapshot.hasData) return const Text('Loading....');

                return Text('Loaded');
              },
            )
            ])));
  }
}

Dependencies in the android\build.gradle file

dependencies {
    classpath 'com.android.tools.build:gradle:3.3.1'
    classpath 'com.google.gms:google-services:4.0.1'
}

Dependencies and new lines added in the android\app\build.gradle file

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-core:16.0.1'
}

apply plugin: 'com.google.gms.google-services'

Dependencies in the pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  intl: 0.15.7
  cloud_firestore: ^0.8.2

I've also downloaded and added the google-services.json file to the android\app folder.

In the Firestore db, I have a collection with id test containing one document.

Expected result: The text "Loaded" should appear under the text "Sup World?"

However, I am getting the above error and it's showing the text "Loading".

Could someone help in getting this resolved please?

9
  • It would be nice if you add pubspec file also such that we can know whether have you added firebase plugin in flutter pubspec.yaml!! And cross check whether you have added classpath 'com.google.gms:google-services:3.0.0' in your project level gradle. Commented Feb 15, 2019 at 12:27
  • @Harshapulikollu - i have updated the thread with the dependencies from the pubspec.yaml file. Commented Feb 15, 2019 at 14:09
  • @Harshapulikollu - regarding project level gradle, do you mean a gradle file at the flutter project level? I don't have one in mine. Commented Feb 15, 2019 at 14:10
  • I mean in your android project level. <flutter project>/android/build.gradle file Commented Feb 15, 2019 at 14:24
  • @Harshapulikollu - yes its in there. I have added it already above. Putting it here again in case it helps: dependencies { classpath 'com.android.tools.build:gradle:3.3.1' classpath 'com.google.gms:google-services:4.0.1' } Commented Feb 15, 2019 at 14:39

2 Answers 2

2

I had posted this on GitHub as well. Running flutter clean on the project and then running the app again fixed it for me.

The url to the GitHub issue. https://github.com/flutter/flutter/issues/28003

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

Comments

0

I got this error when I updated to newer google-services.

Switched back to classpath 'com.google.gms:google-services:3.2.1' and it started working fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.