简体   繁体   English

没有创建 Firebase App - 调用 Firebase.initializeApp()

[英]No Firebase App has been created - call Firebase.initializeApp()

I am trying to run my app and it is giving the following error我正在尝试运行我的应用程序,但出现以下错误

[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() [core/no-app] 没有创建 Firebase App '[DEFAULT]' - 调用 Firebase.initializeApp()

I have already called firebase.initializeApp() but still the error is same.我已经调用firebase.initializeApp()但错误仍然相同。 here is my code of main file这是我的主文件代码

    void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => AppointmentsProvider(),
      child: MaterialApp(
        title: 'Car Wash App',
        theme: ThemeData(
          primarySwatch: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
         
        ),
        home: FutureBuilder(
          future: Firebase.initializeApp(),
          builder: (ctx, snap) =>
              snap.connectionState == ConnectionState.waiting
                  ? Center(
                      child: Text('Loading...'),
                    )
                  : StreamBuilder(
                      stream: FirebaseAuth.instance.authStateChanges(),
                      builder: (ctx, snapShot) =>
                          snapShot.hasData ? HomePage() : UserAuth(),
                    ),
        ),
        routes: {
          HomePage.routeName: (_) => HomePage(),
          HistoryPage.routeName: (_) => HistoryPage(),
          MyAppointments.routeName: (_) => MyAppointments(),
          PackagesPage.routeName: (_) => PackagesPage(),
          VehicleType.routeName: (_) => VehicleType(),
          SlotPage.routeName: (_) => SlotPage(),
          ExtraServicesPage.routeName: (_) => ExtraServicesPage(),
          SummaryPage.routeName: (_) => SummaryPage(),
          DetailedScreen.routeName: (_) => DetailedScreen(),
          PaymentMethodScreen.routeName: (_) => PaymentMethodScreen(),
        },
      ),
    );
  }
}

Any kind of help is much appreciated.非常感谢任何形式的帮助。 Thank you谢谢

You should initialise it in main().您应该在 main() 中对其进行初始化。

For example:例如:

import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(MyApp());
}

This link might be helpful for you.此链接可能对您有所帮助。

If the above answers don't help, you can solve the problem by following steps:如果上述答案没有帮助,您可以通过以下步骤解决问题:

delete the project and take backup of lib folder and pubspec.yaml file.
Create a new project with the same name
copy backed up files to the newly created project.
run flutter pub get
you are good to go

It literally solved my problem.它从字面上解决了我的问题。 I hope this will help.我希望这将有所帮助。

Firebase.initializeApp() is an asynchronous function. Firebase.initializeApp() 是一个异步 function。 You should use "await" to ensure Firebase initialization.您应该使用“等待”来确保 Firebase 初始化。 And use WidgetsFlutterBinding.ensureInitialized() to prevent flutter errors.并使用 WidgetsFlutterBinding.ensureInitialized() 来防止 flutter 错误。

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

The problem is that you have configure firebase in your flutter project but you have not initialized it before the app starts.问题是您在 flutter 项目中配置了 firebase,但在应用程序启动之前您尚未对其进行初始化。

You need to initialize the firebase sdk asynchronously.您需要异步初始化 firebase sdk。 This is how to go about it.这是如何 go 关于它的。

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

This error is know to occur when you fail to add the required dependencies in both your android side of things in project and app level build.gradle files当您未能在项目和应用程序级别 build.gradle 文件中的 android 方面添加所需的依赖项时,就会发生此错误

  1. Check your android/build.gradle file.检查你的 android/build.gradle 文件。 Inside dependecies add内部依赖添加

    classpath 'com.google.gms:google-services:4.3.14' (use latest version)类路径 'com.google.gms:google-services:4.3.14'(使用最新版本)

  2. Go to app/build.gradle file. Go 到 app/build.gradle 文件。 Add the plugin outside dependencies添加插件外部依赖

    apply plugin: 'com.google.gms.google-services'应用插件:'com.google.gms.google-services'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有创建 Firebase App '[DEFAULT]' - 尽管正在初始化 Firebase,但调用 Firebase.initializeApp()) - No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()) although Firebase is being initialized 没有创建 Firebase App '[DEFAULT]' - 在 Flutter 和 Firebase 调用 Firebase.initializeApp() - No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() in Flutter and Firebase 没有创建 Firebase App '[DEFAULT]' - 调用 Firebase.initializeApp() -Flutter - No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() -Flutter 没有 Firebase 应用程序“[DEFAULT]”已创建 - 在 Flutter 中调用 Firebase.initializeApp() - No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() in Flutter React Native 错误:没有创建 Firebase App '[DEFAULT]' - 调用 firebase.initializeApp() - React Native Error: No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp() Firebase 构建消费者异常<usermanager> // [core/no-app] 没有创建 Firebase App '[DEFAULT]' - 调用 Firebase.initializeApp()</usermanager> - Firebase Exception building a Consumer<UserManager> // [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() 没有 Firebase 应用程序“[DEFAULT]”已创建 - 调用 Firebase App.initializeApp() - Firebase 存储 - No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() - Firebase Storage Flutter Web - No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) - Flutter Web - No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) 错误:没有 Firebase 应用程序“[DEFAULT]”已创建 - 调用 Firebase App.initializeApp() - Error: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() FirebaseError: Firebase: 否 Firebase App '[DEFAULT]' 已创建 - 调用 Firebase App.initializeApp() {颤动网络} - FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app). {Flutter web}
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM