英文:
Friebase Firestore is not working. Doesn't even throw any errors
问题
以下是您要翻译的内容:
我正在尝试将我的Flutter应用与Firebase连接。我按照他们的教程进行了更改,并仔细检查了应用级别和项目级别的build.gradle文件。已启用Firestore并创建了一个集合。我将google_services.json文件放在android/app目录中。一切都很正常。甚至没有抛出错误。但Firebase控制台没有显示任何更新。以下是我编写的main.dart文件。
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:cake_of_the_day/login.dart';
import 'package:cake_of_the_day/catalogue.dart';
import 'package:cake_of_the_day/cart.dart';
Future
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
CollectionReference cakes = FirebaseFirestore.instance.collection('cakes');
cakes.add({'name':'asdasd', 'age':21}).then((value) => print("done")).catchError((error) {print(error);});
runApp(
MaterialApp(
title: 'Named Routes Demo',
initialRoute: '/',
routes: {
'/': (context) => const LoginScreen(),
'/catalogue': (context) => const Catalogue(),
'/cart' : (context) => const Cart()
},
),
);
}
英文:
I am trying to connect my Flutter app with Firebase. I followed their tutorial made changes and double checked app level and project level build.gradle files. Enabled Firestore and created a collection. I put the google_services.json file in the android/app directory. Everything is fine. It doesn't even throw an error. But the Firebase console doesn't show any updates. The following is the main.dart file I have written.
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:cake_of_the_day/login.dart';
import 'package:cake_of_the_day/catalogue.dart';
import 'package:cake_of_the_day/cart.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
CollectionReference cakes = FirebaseFirestore.instance.collection('cakes');
cakes.add({'name':'asdasd', 'age':21}).then((value) => print("done")).catchError((error) {print(error);});
runApp(
MaterialApp(
title: 'Named Routes Demo',
// Start the app with the "/" named route. In this case, the app starts
// on the FirstScreen widget.
initialRoute: '/',
routes: {
// When navigating to the "/" route, build the FirstScreen widget.
'/': (context) => const LoginScreen(),
// When navigating to the "/second" route, build the SecondScreen widget.
'/catalogue': (context) => const Catalogue(),
'/cart' : (context) => const Cart()
},
),
);
}
答案1
得分: 0
我将我的手机的网络从Wi-Fi更改为移动数据。现在它可以正常工作。
英文:
I changed my mobile's network form Wifi to Mobile Data. And it works now.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论