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?