Firebase Firestore无法正常工作。甚至没有抛出任何错误。

huangapple go评论63阅读模式
英文:

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 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',
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.

huangapple
  • 本文由 发表于 2023年4月13日 23:54:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76007471.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定