Я пытаюсь выполнить очень простое упражнение, подключив мое основное Флаттер приложение к Cloud Firestore (в Firebase).
Я следовал инструкциям относительно установки.Однако я получаю следующую ошибку:
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.
Мой код флаттера:
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');
},
)
])));
}
}
Зависимости в файле android \ build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.0.1'
}
Зависимостии новые строки добавлены в файл android \ app \ build.gradle
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'
Зависимости в pubspec.yaml
dependencies:
flutter:
sdk: flutter
intl: 0.15.7
cloud_firestore: ^0.8.2
Я также скачал и добавил google-services.json файл в папку android \ app.
В базе данных Firestore у меня есть коллекция с идентификатором test , содержащая один документ.
Ожидаетсярезультат: текст "Loaded" должен появиться под текстом "Sup World?"
Однако я получаю вышеуказанную ошибку, и он показывает текст "Загрузка".
Может ли кто-нибудь помочь вкак решить эту проблему, пожалуйста?