所以首先,我花了很多时间将Flutter 连接到 firebase 基地,我没有得到之前的错误,但我也不知道它是否连接.首先,错误出现在build.gradle文件中.我想这个问题已经解决了.现在它显示"跳过XX帧:应用程序可能在其主线程上做了太多工作."

我提供了所有必要的代码.我希望它能修好,我已经用了这么多天了.

Main.dart

import 'package:firebase_core/firebase_core.dart';
import 'package:ableeasefinale/pages/UI/parentPage.dart';
import 'package:flutter/material.dart';
import 'theme/theme.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
  home: const ParentPage(),
  theme: lightMode,
  darkTheme: darkMode,
  themeMode: ThemeMode.dark,
    );
  }
}

android/build.gradle

buildscript {
ext.kotlin_version = '1.9.20'
repositories {
    google()
    mavenCentral()
}

dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.google.gms:google-services:4.4.1'
}

}

android/app/build.gradle

plugins{
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
id 'com.google.gms.google-services'

}    
dependencies {
    implementation platform('com.google.firebase:firebase-bom:32.7.2')
}

Debug Console Debug Console after running

在最后一次运行中,DEBUG还显示以下消息:"已跳过XX帧:应用程序可能在其主线程上做了太多工作."

如果有人知道一个更好的教程来连接它,请提供,这将是有帮助的

推荐答案

初始化Firebase时,需要在main()中添加Firebase Options:

await Firebase.initializeApp(
    options: FirebaseOptions(
      apiKey: "ApiKey",
      appId: "AppId",
      messagingSenderId: "MessagingSenderId",
      projectId: "ProjectId",
    ),
  );

更好的方法是使用FlutterFire Cli将Firebase重新配置为您的项目,它将根据您 Select 的平台生成Firebase_options.dart文件:

await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);

Flutter相关问答推荐

类型flatter doctor get zsh:未找到命令:macO中flatter

在Flutter中创建具有固定行的压缩水平列表

build_runner显示错误没有为类ClassDeclaration定义getter宏关键字'

为什么要在值列表中两次放入空安全性

将列表<;Events>;从Flutter 应用程序中的函数传回EventLoader属性时出错

在Flutter 中更改扩展瓷砖的高度

有没有可能不在BlocBuilder中重新构建内容?

无法构建AndroidBundle 包或iOS等

怎么才能像这样在摆动着这些曲线呢?

在Flutter 小部件测试中找不到框中的AssetImage装饰

导航回上一页会将我带回Ffltter应用程序中的登录页面

将状态维护到 asyncNotifier

状况不佳 - Cubit

如何将 List 转换为 String []?

Positioned 的宽度或 SizedBox 的宽度都不适用于堆栈小部件 - Flutter

如何在屏幕按钮中排列 row() (我想在按钮中放置屏幕导航图标)

我想在数组中添加项目

gridview 的所有按钮都应该在Flutter 中适合其父容器

在 Flutter Bloc 中具有称为 status 的属性的一种状态或不同的状态,哪个更可取?

参数类型Future>不能分配给参数类型Future>?