ios Flutter和Firebase连接在Firebase.initializeApp()处停止

vuktfyat  于 2023-05-08  发布在  iOS
关注(0)|答案(2)|浏览(245)

我正在开发一个多平台应用程序,使用flutter for android和ios。现在我正在尝试将我的应用程序与Firebase连接。我做了每一个必要的步骤,包括,添加google_services.json,添加firebase核心,auth,核心web,云firestore。但由于某种原因,我的应用程序停在await Firebase.initializeApp();行。它显示错误Error: Assertion failed:
这是我的main.dart

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'features/auth/welcome_screen.dart';

Future main() async {
  WidgetsFlutterBinding.ensureInitialized();
  print("////////////////////////////////");
  await Firebase.initializeApp();
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'UniCompanion',
      debugShowCheckedModeBanner: false,
      home: WelcomeScreen(),
    );
  }
}

这里是错误:

Error: Assertion failed:
file:///C:/Users/rudro/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_core_web-2.4.0/li
b/src/firebase_core_web.dart:256:11
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/priva
te/ddc_runtime/errors.dart 266:49  throw_
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/priva
te/ddc_runtime/errors.dart 29:3    assertFailed
packages/firebase_core_web/src/firebase_core_web.dart 256:18
initializeApp
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch
/async_patch.dart 45:50            <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1660:54       
runUnary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 147:18 
handleValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 767:44 
handleValueCallback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 796:13 
_propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 567:5  
[_completeWithValue]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future.dart 528:22      
<fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1660:54       
runUnary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 147:18 
handleValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 767:44 
handleValueCallback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 796:13 
_propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 567:5  
[_completeWithValue]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 640:7  
callback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 
40:11                              _microtaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 
49:5                               _startMicrotaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch
/async_patch.dart 166:15           <fn>

请帮我一下。
我尝试添加所有依赖项,例如在pubspec.yaml文件中添加这些行

firebase_auth: ^4.5.0
  cloud_firestore: ^4.6.0
  firebase_analytics: ^10.3.0
  firebase_core: ^2.11.0
  firebase_core_web: ^2.4.0
qmb5sa22

qmb5sa221#

看起来你缺少了Web应用的配置,它需要在JavaScript文件中,如本文档中所示,为Web应用初始化Flutter SDK for Firebase。
老实说,我现在建议将初始化放在Dart代码中-通过遵循将Firebase添加到Flutter应用程序的设置说明。

ddhy6vgd

ddhy6vgd2#

在void main(runApp())部分的main.dart中,添加以下内容并尝试

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

相关问题